james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1148686 - /james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
Date Wed, 20 Jul 2011 10:26:42 GMT
Author: norman
Date: Wed Jul 20 10:26:39 2011
New Revision: 1148686

URL: http://svn.apache.org/viewvc?rev=1148686&view=rev
Log:
Fix possible NPE when try to fetch a message for an unknown uid. See MAILBOX-107

Modified:
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java?rev=1148686&r1=1148685&r2=1148686&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
(original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
Wed Jul 20 10:26:39 2011
@@ -155,7 +155,7 @@ public class MaildirMessageMapper extend
             MaildirMessageName messageName = folder.getMessageNameByUid(mailboxSession, uid);
         
              ArrayList<Message<Integer>> messages = new ArrayList<Message<Integer>>();
-             if (messageName != null) {
+             if (messageName != null && messageName.getFile().exists()) {
                  messages.add(new MaildirMessage(mailbox, uid, messageName));
              }
              return messages;
@@ -408,38 +408,40 @@ public class MaildirMessageMapper extend
 
                     try {
                         MaildirMessageName messageName = folder.getMessageNameByUid(mailboxSession,
member.getUid());
-                        File messageFile = messageName.getFile();
-                        // System.out.println("save existing " + message +
-                        // " as " + messageFile.getName());
-                        messageName.setFlags(member.createFlags());
-                        // this automatically moves messages from new to cur if
-                        // needed
-                        String newMessageName = messageName.getFullName();
+                        if (messageName != null) {
+                            File messageFile = messageName.getFile();
+                            // System.out.println("save existing " + message +
+                            // " as " + messageFile.getName());
+                            messageName.setFlags(member.createFlags());
+                            // this automatically moves messages from new to cur if
+                            // needed
+                            String newMessageName = messageName.getFullName();
 
-                        File newMessageFile;
+                            File newMessageFile;
                         
-                        // See MAILBOX-57
-                        if (newFlags.contains(Flag.RECENT)) {
-                            // message is recent so save it in the new folder
-                            newMessageFile = new File(folder.getNewFolder(), newMessageName);
-                        } else {
-                            newMessageFile = new File(folder.getCurFolder(), newMessageName);
-                        }
-                        long modSeq;
-                        // if the flags don't have change we should not try to move the file
-                        if (newMessageFile.equals(messageFile) == false) {
-                            FileUtils.moveFile(messageFile, newMessageFile );
-                            modSeq = newMessageFile.lastModified();
-
-                        } else {
-                            modSeq = messageFile.lastModified();
-                        } 
-                        member.setModSeq(modSeq);
+                            // See MAILBOX-57
+                            if (newFlags.contains(Flag.RECENT)) {
+                                // message is recent so save it in the new folder
+                                newMessageFile = new File(folder.getNewFolder(), newMessageName);
+                            } else {
+                                newMessageFile = new File(folder.getCurFolder(), newMessageName);
+                            }
+                            long modSeq;
+                            // if the flags don't have change we should not try to move the
file
+                            if (newMessageFile.equals(messageFile) == false) {
+                                FileUtils.moveFile(messageFile, newMessageFile );
+                                modSeq = newMessageFile.lastModified();
+
+                            } else {
+                                modSeq = messageFile.lastModified();
+                            } 
+                            member.setModSeq(modSeq);
                         
-                        updatedFlags.add(new UpdatedFlags(member.getUid(), modSeq, originalFlags,
newFlags));
+                            updatedFlags.add(new UpdatedFlags(member.getUid(), modSeq, originalFlags,
newFlags));
 
-                        long uid = member.getUid();
-                        folder.update(mailboxSession, uid, newMessageName);
+                            long uid = member.getUid();
+                            folder.update(mailboxSession, uid, newMessageName);
+                        }
                     } catch (IOException e) {
                         throw new MailboxException("Failure while save Message " + member
+ " in Mailbox " + mailbox, e);
                     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message