Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Javamail folder message upper limit???

843834Jun 10 2009 — edited Jun 10 2009
Hi All,

I had posted a message back in 2007 related to the code below. Is it possible that whenever the number of messages in my INBOX reaches 65535 this code fails when opening the folder? Because nothing has changed on the Exchange server and the message I get is "Java exception: java.lang.IllegalStateException: This operation is not allowed on a closed folder". I am unable to update the version of javamail because the Oracle database has an old version of JDK which I cannot update.

Here is the trace:

* OK Microsoft Exchange IMAP4rev1 server version 5.5.2653.23 (xxxxx.bbbbb.com) ready
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LITERAL+ LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE AUTH=NTLM
A0 OK CAPABILITY completed.
A1 LOGIN xxxx yyyy
A1 OK LOGIN completed.
A2 LIST "" "Public Folders/branch_alarms_cmms"
* LIST (\Marked) "/" "Public Folders/branch_alarms_cmms"
A2 OK LIST completed.
JAVA_DEBUG: Open in READ_ONLY mode.
DEBUG: connection available -- size: 1
A3 EXAMINE "Public Folders/branch_alarms_cmms"
A3 NO Unspecified error

Thanks in advance,
Sinan
create or replace and compile
 java source named "DownloadAlarms"
 as
 import java.text.*;
 import java.util.*;
 import java.io.*;
 import javax.mail.*;
 import javax.mail.UIDFolder;
 import javax.mail.FetchProfile;
 import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.Session;
 import javax.mail.Store;
 import javax.mail.event.*;
 import javax.activation.*;

 import oracle.sql.*;
 import oracle.sqlj.runtime.Oracle;

 public class DownloadAlarms {

    public  static final Locale US = new Locale("en","US","");
    //public  static UIDFolder curUF;

    public static oracle.sql.NUMBER
       monitoralarm(String email_host
                   ,String email_usr
                   ,String email_pwd
                   ,String email_box
                   ,long   msglastUID) throws MessagingException
    {
       int  rc = 0;
       int  mcount = 0;
       //int  rt_error = 1;

          Properties props = System.getProperties();

          // Get a Session object
          Session session = Session.getInstance(props, null);
          session.setDebug(true);

          // Get a Store object
          Store store = session.getStore("imap");


       try {

          // Connect
          store.connect(email_host, email_usr, email_pwd);

          // Open the Folder
          Folder folder = store.getFolder(email_box);
          if (folder == null || !folder.exists()) {
             System.out.println("Folder does not exist!");
             //System.exit(1);
          }

          if(!(folder instanceof UIDFolder)){
             System.out.println(
             "JAVA_DEBUG:This provider or this folder does not support UIDs. The program will exit now.");
             //System.exit(1);
          }

          UIDFolder ufolder = (UIDFolder)folder;

          System.out.println("JAVA_DEBUG: Open in READ_ONLY mode.");

          try
          {
              folder.open(Folder.READ_ONLY);
          }
          catch(Exception e)
          {
              System.out.println("Could not open the folder as READ_ONLY");
          }

          //int numofMessages = folder.getMessageCount();

          if (folder.getMessageCount() == 0){
             System.out.println("JAVA_DEBUG:Empty folder.");
             folder.close(false);
             store.close();
             //System.exit(1);
          }

          // Get emails with the UIDs
          Message[] msgs = ufolder.getMessagesByUID(msglastUID + 1, UIDFolder.LASTUID);

          String msg_subj = "";
          String msg_sent = "";
          String sender   = "";
          String mbody  = "";

          SimpleDateFormat formatter;
          long uidMsg = 0;
          formatter = new SimpleDateFormat("MM.dd.yyyy H:mm:ss", US);

          int k=0;
          for (int i = 0; i < msgs.length; i++) {
              k=i;
             // get the subject
             try{
                msg_subj = msgs.getSubject();
}catch(Exception e){
msg_subj = "UNKNOWN";
}
// get the sender
try{
sender = msgs[i].getFrom()[0].toString();
}catch(Exception e){
sender = "UNKNOWN";
}

// get the content
try{
mbody = msgs[i].getContent().toString();
}catch(Exception e){
mbody = "UNKNOWN";
}

try{
uidMsg = ((UIDFolder)folder).getUID(msgs[i]);
}catch(Exception e){
uidMsg = 0;
}

System.out.println("JAVA_DEBUG:Inserting...!");

//insert into oracle Dw_alarms_tmp table
try{
#sql {INSERT INTO dw_alarms_tmp(
AL_UID
, AL_FROM
, AL_TEXT
, AL_DATE
, AL_BODY ) VALUES(
:IN( uidMsg )
, :IN( sender )
, :IN( msg_subj )
, :IN( formatter.format(msgs[i].getSentDate()) )
, :IN( mbody )
) };

if( i % 500 == 0 ){
System.out.println("JAVA_DEBUG:Commiting inside the loop...!");
#sql { COMMIT };
}

}catch(Exception e){
;
}

System.out.println("JAVA_DEBUG:Commiting outside of the loop...!");
#sql { COMMIT };

}

System.out.println("JAVA_DEBUG:Closing folder...!");

if (folder != null && folder.isOpen())
try {
folder.close(false);
} catch (MessagingException e) {
System.out.println("JAVA_DEBUG:[COULDNT_CLOSE_FOLDER]" + e.getMessage());
}

System.out.println("JAVA_DEBUG:Closing store...");

// Close the store
if (store != null)
try {
store.close();
} catch (MessagingException e) {
System.out.println("JAVA_DEBUG:[COULDNT_CLOSE_CONNECTION]" + e.getMessage());
}

System.out.println("JAVA_DEBUG:Closed everthing.");

store = null;
folder = null;

System.out.println("JAVA_DEBUG:Assigning null to objects.");

} catch (Exception ex) {
System.out.println("JAVA_DEBUG:The last catch before Finally - Unhandled exception : " + ex.getMessage());
ex.printStackTrace();
//return new oracle.sql.NUMBER(rt_error);
}
finally
{
// Close the store
if (store != null)
try {
store.close();
System.out.println("JAVA_DEBUG:Closed store in the FINALLY section.");
} catch (MessagingException e) {
System.out.println("JAVA_DEBUG:[COULDNT_CLOSE_CONNECTION] in finally section." + e.getMessage());
}
return new oracle.sql.NUMBER(mcount);
}
}
}
Edited by: Sin@n on Jun 10, 2009 4:37 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 8 2009
Added on Jun 10 2009
1 comment
346 views