chrislee35/IMAPCrypt

NullPointerException when email doesn't contain a proper date

Closed this issue · 10 comments

When i try it from the commandline whit my Spamfolder its looks valid but after some time its stop whit a NullPointerException.

  • win7
  • java version "1.8.0_60"
  • Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
  • Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
...
2015-09-12 05:39:54 INFO  IMAPCrypt:327 -   Did not match all the filters
2015-09-12 05:39:55 INFO  IMAPCrypt:315 - Message #172 on Sat Sep 05 16:22:42 CEST 2015: VIDEO anschauen: Software verdi
ent f³r Sie 439 Euro pro Tag
2015-09-12 05:39:55 INFO  IMAPCrypt:327 -   Did not match all the filters
2015-09-12 05:39:55 INFO  IMAPCrypt:315 - Message #173 on Sat Sep 05 17:14:35 CEST 2015: Vom Bettler zum Multimillionõr
in 2 Jahren! VIDEO zum NACHMACHEN
2015-09-12 05:39:55 INFO  IMAPCrypt:327 -   Did not match all the filters
2015-09-12 05:39:56 INFO  IMAPCrypt:315 - Message #174 on null: Be young, have fun, taste Love
java.lang.NullPointerException
        at org.dhs.chrislee.DateBasedMessageEvaluationCallback.isEncryptableMessage(DateBasedMessageEvaluationCallback.java:60)
        at org.dhs.chrislee.IMAPCrypt.encrypt(IMAPCrypt.java:325)
        at org.dhs.chrislee.IMAPCrypt.main(IMAPCrypt.java:589)

If i try the gui at win7

C:\Users\root\Downloads>java -jar imapcrypt-2.0.2.jar
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at org.dhs.chrislee.imapgui.KeySelectorPanel.<init>(KeySelectorPanel.java:52)
        at org.dhs.chrislee.imapgui.KeySelectorPanel.<init>(KeySelectorPanel.java:38)
        at org.dhs.chrislee.imapgui.groups.RecipientPanel.<init>(RecipientPanel.java:36)
        at org.dhs.chrislee.imapgui.IMAPGui.<init>(IMAPGui.java:77)
        at org.dhs.chrislee.imapgui.IMAPGui$4.run(IMAPGui.java:326)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

I'll take a look at this tomorrow. Thanks for letting me know.

Hideio, both of these are excellent bug finds. The first has to do when the message doesn't present a valid date and the second is caused by not being able to find a secret key ring. It will take time to fix both of these because I have to create a testing environment that will trigger both of these problems.
I think that I will split this issue into two issues. I'll work on the GUI-launch issue (which is really a GPG secret key issue) first.

I couldn't reproduce this bug exactly, but I did find interesting ways to make my imap server crash... I added a "likely" patch to try to work around the missing date issue. Look to version 2.0.3.

Thank you Command Line works now.
Edit: find some exceptions for some mails.

...
llegalWriteException: IMAPBodyPart is read-only
2015-09-14 18:37:46 INFO  IMAPCrypt:316 - Message #69 on Tue Nov 11 12:32:35 CET 2014: Fw: Fwd: Info
2015-09-14 18:37:46 DEBUG IMAPCrypt:341 - Encrypting the MultiPartMime message
2015-09-14 18:37:47 ERROR IMAPCrypt:363 - The message failed to encrypt because of a IllegalWriteException: javax.mail.IllegalWriteException: IMAPBodyPart is read-only
2015-09-14 18:37:47 INFO  IMAPCrypt:316 - Message #70 on Tue Nov 11 12:33:19 CET 2014: Fw: Fwd: Info
2015-09-14 18:37:47 DEBUG IMAPCrypt:341 - Encrypting the MultiPartMime message
2015-09-14 18:37:48 ERROR IMAPCrypt:363 - The message failed to encrypt because of a IllegalWriteException: javax.mail.IllegalWriteException: IMAPBodyPart is read-only
2015-09-14 18:37:48 INFO  IMAPCrypt:316 - Message #71 on Tue Nov 11 12:33:57 CET 2014: Fw: Fwd: Part 2
2015-09-14 18:37:48 DEBUG IMAPCrypt:341 - Encrypting the MultiPartMime message
2015-09-14 18:37:49 ERROR IMAPCrypt:363 - The message failed to encrypt because of a IllegalWriteException: javax.mail.IllegalWriteException: IMAPBodyPart is read-only
2015-09-14 18:37:49 INFO  IMAPCrypt:316 - Message #72 on Tue Nov 11 12:34:31 CET 2014: Fw: Fwd: Part 2
2015-09-14 18:37:49 DEBUG IMAPCrypt:341 - Encrypting the MultiPartMime message
2015-09-14 18:37:50 ERROR IMAPCrypt:363 - The message failed to encrypt because of a IllegalWriteException: javax.mail.IllegalWriteException: IMAPBodyPart is read-only
...

An some second small thing, i need umlauts because Drafts=Entwürfe in german.

javax.mail.FolderNotFoundException: Entw?rfe not found
        at com.sun.mail.imap.IMAPFolder.checkExists(IMAPFolder.java:430)
        at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:1018)
        at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:951)
        at org.dhs.chrislee.IMAPCrypt.encrypt(IMAPCrypt.java:307)
        at org.dhs.chrislee.IMAPCrypt.main(IMAPCrypt.java:590)

Weird! I thought for sure that I had full UTF-8 support. This should be easy to test however. Thanks for finding the bug.

This is strange. I created a folder called INBOX.imapcrypt.tëstüñç and it seemed to work just fine.

2015-09-15 21:46:42 INFO IMAPCrypt:353 - Appending the new, encrypted version of the message into the folder, INBOX.imapcrypt.tëstüñç
...
2015-09-15 21:46:44 INFO IMAPCrypt:316 - Message #14 on Thu Sep 10 16:33:44 JST 2015: Хотите что-то поменять в своем доме?

In thunderbird the imap address folder "Entwürfe" looks like that "imap.gmx.net/Entw%26APw-rfe" maybe thats matter?

So I used Thunderbird to create a subfolder named "Entw%26APw-rfe" and it showed up in my folder list as Entwürfe. Then I ran 2.0.3 on the folder and it encrypted just fine. I'm starting to suspect the IMAP server software on imap.gmx.net (my sleuthing indicates Cyrus). I'm using dovecot for my test server.

It could be how the java code indexes folders. Perhaps I'm not putting special folders in their proper place. I couldn't figure out how to register an account on gmx.net... I'll try again tomorrow.

2015-09-16 21:49:42 INFO IMAPCrypt:353 - Appending the new, encrypted version of the message into the folder, INBOX.imapcrypt.Entwürfe

GMX have a English portal for *.com emails too https://www.gmx.com/ . But im not 100% sure they use the exact same setups for they servers in europe/america.