Checking IMAP folders
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, June 5, 2001 08:12 AM

Hello I have written a small piece of code that checks the read/unread content of a mailbox. This works fine, but it is a little slow. I am hoping to eventually include this functionality into a portal (jsp based) but I am trying to optimise the procedure first. From the below code can anyone give some suggestions ? thanks Eoin //code import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class checkIMAP { public static void main(String args[]) throws Exception { Vector result = new Ve   More>>

Hello




I have written a small piece of code that checks the read/unread content of a mailbox.



This works fine, but it is a little slow. I am hoping to eventually include this functionality into a portal (jsp based) but I am trying to optimise the procedure first.



From the below code can anyone give some suggestions ?



thanks



Eoin



//code


import javax.mail.*;

import javax.mail.internet.*;

import java.util.*;



public class checkIMAP

{

public static void main(String args[]) throws Exception

{

Vector result = new Vector();

String host = args[2];

String username = args[0];

String password = args[1];

try

{

result = doCheck(username,password,host);

System.out.println(result.toString());

}

catch(NoSuchProviderException a)

{

System.out.println("NoSuchProviderException "+a.toString());

}

catch(MessagingException b)

{

System.out.println("MessagingException "+b.toString());

}

}

public static Vector doCheck(String username,String password,String host) throws
NoSuchProviderException,MessagingException

{

Vector answer = new Vector();

try

{

// Get session

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



// Get the store

Store store = session.getStore("imap");

store.connect(host, username, password);



// Get folder

Folder folder = store.getFolder("INBOX");

folder.open(Folder.READ_ONLY);



// Get Count

int count = folder.getMessageCount();

int total = count;

count = folder.getUnreadMessageCount();

int unread = count;



// Close connection

folder.close(false);

store.close();



answer.addElement(new Integer(total));

answer.addElement(new Integer(unread));



}

catch(NoSuchProviderException a) { throw new NoSuchProviderException();}

catch(MessagingException b) {throw new MessagingException(); }



return answer;

}

}

   <<Less

Re: Checking IMAP folders

Posted By:   John_Zukowski  
Posted On:   Wednesday, June 6, 2001 08:44 AM

Since you ARE using IMAP, you can keep a reference to the IMAP folder around in the servlet session, instead of fetching it each time the method is called.
About | Sitemap | Contact