Showing message with webservice

The requirement is like Dot net environment needs to call a webservice to access mails of a certain user from java mail.

I wrote a webservice that connects to IMAP and able to fetch certain message details. The webservice returns a string(say resultString

) which includes details like From, Size, Received date and subject.

But, the challenging task is how is that I return a message?Since message could be of single part or multipart, If the message is in text format I could append it to string resultString

and return. But what if the message has attachments? How would and what should I be returning in that case?

I hope I made my point clear. Has any one have any suggestion. I appreciate and solicit your great idea.

Thanks.

Rk.

Heres the sample webservice i wrote:

public String displayDet(String hostname,String userEmail,String password)

throws Exception{

try{

m_MailSession = Session.getInstance(System.getProperties(),null);

//setup store and connect to it

String proto ="imap";

m_Store = m_MailSession.getStore(proto);

m_Username=userEmail;

m_PostOfficeHost=hostname;

m_Store.connect(m_PostOfficeHost,m_Username,password);

System.out.println(m_Username+"@"+m_PostOfficeHost+"SUCCESSFUL LOGIN");

m_Inbox = m_Store.getFolder("INBOX");

}catch (Exception e){e.printStackTrace();}

String resultString;

StringBuffer sbf =new StringBuffer();

m_Inbox.open(Folder.READ_ONLY);

Message msg[] = m_Inbox.getMessages();

for(int index=0;index<msg.length;index++){

sbf.append("From : "+msg[index].getFrom());//to be modified

sbf.append(",");

sbf.append("Message no. "+index+" Subject :"+msg[index].getSubject());

sbf.append(",");

sbf.append("Date :"+msg[index].getReceivedDate());

sbf.append(",");

sbf.append(",");

sbf.append("Size :"+msg[index].getSize());

sbf.append(",");

//sbf.append("Message body) :"+msg[index].getBody());

//sbf.append(",");

}

m_Inbox.close(false);

try{//close store

m_Store.close();}catch (Exception ex){ex.printStackTrace();}

resultString=sbf.toString();

return resultString;

}//displayDet

>

[3565 byte] By [passion_for_javaa] at [2007-11-27 7:40:38]
# 1

Well, there's three obvious choices.

1. You return the entire MIME message, just like POP3 does.

2. You invent a web service protocol that's as rich as IMAP and

allows you to access the various parts of the message.

3. You transform the MIME message structure into an equivalent

XML data structure and return that.

If you're determined to use a web service protocol instead of

an existing mail protocol, #1 is certainly the easiest.

bshannona at 2007-7-12 19:21:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...