This method returns MailMessage object
*/
public MailMessage getMailMessage( int userId, HashMap preference)
{
MailMessage mailmessage = new MailMessage();
try
{
Integer messageid = (Integer)preference.get( "MessageID" );
int id = messageid.intValue();
//System.out.println( "*****Message ID***** " + id );
CVDal cvdl = new CVDal(dataSource);
Collection v = null;
cvdl.setSql("email.getcreatetable");
cvdl.executeUpdate();
cvdl.clearParameters();
cvdl.setSql("email.getmailinsert");
cvdl.setInt( 1, id );
cvdl.executeUpdate();
cvdl.clearParameters();
cvdl.setSql("email.getmailupdate1");
cvdl.executeUpdate();
cvdl.clearParameters();
cvdl.setSql("email.getmailselect");
v = cvdl.executeQuery();
cvdl.clearParameters();
cvdl.setSql("email.getmaildrop");
cvdl.executeUpdate();
cvdl.clearParameters();
cvdl.destroy();
//System.out.println( " ***** Main Query Complete ***** " );
Iterator it = v.iterator();
HashMap hm = ( HashMap )it.next();
MailAccount mailaccount = new MailAccount();
int AccountID = ((Long)hm.get( "AccountID" )).intValue() ;
//System.out.println( "MailAccount" + AccountID );
/**
mailmessage.setAccountID( AccountID );
if ( ( ((Long)hm.get( "AttachmentID" )).intValue() ) != 0)
{
mailmessage.setAttachmentID( ((Long)hm.get( "AttachmentID" )).intValue() ) ;
}
*/
if ( (String)hm.get( "Body" ) != null )
{
//System.out.println( "Body" + (String)hm.get( "Body" ) );
mailmessage.setBody( (String)hm.get( "Body" ) ) ;
}
// mailmessage.setFolder( ((Long)hm.get( "folder" )).intValue() ) ;
if ( hm.get( "FromIndividual" ) != null )
{
mailmessage.setFromIndividual( ((Long)hm.get( "FromIndividual" )).intValue() );
}
if ( (String)hm.get( "Headers" ) != null )
{
// IQ Added for headers
//System.out.println( "Headers" + (String)hm.get( "Headers" ) );
String allHeader = (String)hm.get( "Headers" );
mailmessage.setHeaders( allHeader );
/*
if (allHeader != null && allHeader.length() > 0)
{
StringTokenizer st = new StringTokenizer(allHeader,Constants.EH_HEADER_DELIMETER);
while (st.hasMoreTokens()) {
String fullHeader = st.nextToken();
int eqIndx = fullHeader.indexOf(Constants.EH_KEYVALUE_DELEMETER);
mailmessage.setHeadersHM(fullHeader.substring(0,eqIndx).trim(),fullHeader.substring(eqIndx+1).trim());
}
}
*/
}
if ( (String)hm.get( "Importance" ) != null )
{
//System.out.println( "Importance" + (String)hm.get( "Importance" ) );
mailmessage.setImportance( (String)hm.get( "Importance" ) ) ;
}
if ( ( Timestamp )hm.get( "MessageDate" ) != null )
{
//System.out.println( "MessageDate" + ( Timestamp )hm.get( "MessageDate" ) );
mailmessage.setMessageDate( ( Timestamp )hm.get( "MessageDate" ) );
}
if ( ( ((Long)hm.get( "MessageID" )).intValue() ) != 0)
{
//System.out.println( "MessageID" + ( ((Long)hm.get( "MessageID" )).intValue() ) );
mailmessage.setMessageID( ((Long)hm.get( "MessageID" )).intValue() ) ;
}
if ( ( String )hm.get( "Priority" ) != null )
{
//System.out.println( "Priority" + ( String )hm.get( "Priority" ) );
mailmessage.setPriority( (String)hm.get( "Priority" ) ) ;
}
// mailmessage.setStatus( (String)hm.get( "Status" ) ) ;
if ( ( String )hm.get( "Subject" ) != null )
{
//System.out.println( "Subject" + ( String )hm.get( "Subject" ) );
mailmessage.setSubject( (String)hm.get( "Subject" )) ;
}
mailmessage.setTheMailAccount( mailaccount ) ;
if ( ( String )hm.get( "MailFrom" ) != null )
{
//System.out.println( "MailFrom" + ( String )hm.get( "MailFrom" ) );
mailmessage.setMailFrom( (String)hm.get("MailFrom")) ;
}
ArrayList to = new ArrayList();
ArrayList cc = new ArrayList();
ArrayList bcc = new ArrayList();
// to
CVDal cvdlto = new CVDal(dataSource);
Collection vto = null;
cvdlto.setSql("email.getmailaddressTO");
cvdlto.setInt( 1 , id );
vto = cvdlto.executeQuery();
cvdlto.clearParameters();
cvdlto.destroy();
Iterator itto = vto.iterator();
while( itto.hasNext() )
{
HashMap hmto = ( HashMap )itto.next();
String addto = (String) hmto.get( "Address" );
//System.out.println( addto );
to.add ( new MailAddress( addto ) );
}
// CC
CVDal cvdlcc = new CVDal(dataSource);
Collection vcc = null;
cvdlcc.setSql("email.getmailaddressCC");
cvdlcc.setInt( 1 , id );
vcc = cvdlcc.executeQuery();
cvdlcc.clearParameters();
cvdlcc.destroy();
Iterator itcc = vcc.iterator();
int i=0 ;
while( itcc.hasNext() )
{
i++;
HashMap hmcc = ( HashMap )itcc.next();
String addcc = (String) hmcc.get( "Address" );
//System.out.println( addcc );
cc.add ( new MailAddress( addcc ) );
}
//BCC
// change from shirish ,linesh
CVDal cvdlbcc = new CVDal(dataSource);
Collection vbcc = null;
cvdlbcc.setSql("email.getmailaddressBCC");
cvdlbcc.setInt( 1 , id );
vbcc = cvdlbcc.executeQuery();
cvdlbcc.clearParameters();
cvdlbcc.destroy();
Iterator itbcc = vbcc.iterator();
while( itbcc.hasNext() )
{
HashMap hmbcc = ( HashMap )itbcc.next();
String addbcc = (String) hmbcc.get( "Address" );
//System.out.println("bcc"+ addbcc );
bcc.add ( new MailAddress( addbcc ) );
}
//End change from shirish ,linesh
mailmessage.setTo( to ) ;
mailmessage.setCc( cc) ;
mailmessage.setBcc( bcc) ;
// mailmessage.setBcc( (String)hm.get( "bcc" ) ) ;
/** Attachment added on 29-07-2003 */
CVDal cvdlattch = new CVDal(dataSource);
Collection attch = null;
cvdlattch.setSql("email.getallattachments");
cvdlattch.setInt( 1, id );
attch = cvdlattch.executeQuery();
cvdlattch.clearParameters();
cvdlattch.destroy();
Iterator itattch = attch.iterator();
ArrayList arrayattch = new ArrayList();
while( itattch.hasNext() )
{
HashMap hmattach = ( HashMap )itattch.next();
int AttachmentID = ( (Long) hmattach.get( "AttachmentID" )).intValue() ;
int MessageID = ((Long) hmattach.get( "MessageID" )).intValue();
int FileID = ((Long) hmattach.get( "FileID" )).intValue();
String FileName = (String) hmattach.get( "FileName" );
//System.out.println(AttachmentID + " "+MessageID + " "+FileID+ " "+FileName );
Attachment a = new Attachment( AttachmentID, MessageID, FileID, FileName );
arrayattch.add( a );
}
mailmessage.setAttachmentID( arrayattch );
/** attchment End */