Skip to content

Commit

Permalink
fixed issue #2 and #3, crashes upon missing date in email or missing …
Browse files Browse the repository at this point in the history
…gpg keys
  • Loading branch information
chrislee35 committed Sep 13, 2015
1 parent 93208a8 commit 61d88f8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/org/dhs/chrislee/DateBasedMessageEvaluationCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public void setInvert(boolean invert) {
*/
public boolean isEncryptableMessage(Message m) throws MessagingException {
java.util.Date today = new java.util.Date();
// What should I do if m.getSentDate() is null?
// (a) set it to the epoch
// (b) set it to current time
// (c) set it to some offset of current time
// (d) set it to OCT 21 2015 04:29
// (e) return false
// (f) return true ** I'm going with this
if(m.getSentDate() == null)
return (! this.invert);

int daysold = (int)((today.getTime() - m.getSentDate().getTime())/(1000*24*60*60));
if(this.invert) {
return ! (daysold >= this.minage && daysold <= this.maxage);
Expand Down
1 change: 1 addition & 0 deletions src/org/dhs/chrislee/IMAPCrypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class IMAPCrypt {
private ArrayList<MessageEvaluationCallback> messageEvaluationCallbacks;
private boolean verbose; // print debug/connection messages?
private static SSLSocketFactory sslSocketFactory = null;
final public static String VERSION = "2.0.3";
final static Logger logger = Logger.getLogger(IMAPCrypt.class);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/org/dhs/chrislee/gnupg/GPGKeyList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void addKeyId(GPGKeyId keyId) {
}

protected static GPGKeyId[] arrayListToArray(ArrayList<GPGKeyId> ids) {
GPGKeyId[] arr = new GPGKeyId[1];
GPGKeyId[] arr = new GPGKeyId[ids.size()];
return ids.toArray(arr);

}
Expand Down
2 changes: 2 additions & 0 deletions src/org/dhs/chrislee/imapgui/IMAPGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class IMAPGui extends JFrame {
*/
public IMAPGui() {
super();

this.setTitle("IMAPCrypt version "+IMAPCrypt.VERSION);

/* create the groups, add them to the GUI,
* create Panels
Expand Down
12 changes: 6 additions & 6 deletions src/org/dhs/chrislee/imapgui/KeySelectorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public KeySelectorPanel(GPGKeyList sec, GPGKeyList pub) {
secretKeyList = sec;
publicKeyList = pub;
selectedKeyIds = new GPGKeyList();
for(GPGKeyId kid : secretKeyList.getKeyIDArray())
selectedKeyIds.addKeyId(kid);
if(secretKeyList != null)
for(GPGKeyId kid : secretKeyList.getKeyIDArray())
selectedKeyIds.addKeyId(kid);
int uidColumnWidth = 500;

String[] columnNames = {"Use?", "KeyId", "UID", "KID"};
ArrayList<Object[]> data = new ArrayList<Object[]>();
for(GPGKeyId kid : sec.getKeyIDArray()) {
addGPGKeyIDToModel(kid, data);

}
if(secretKeyList != null)
for(GPGKeyId kid : sec.getKeyIDArray())
addGPGKeyIDToModel(kid, data);
for(GPGKeyId kid : pub.getKeyIDArray())
addGPGKeyIDToModel(kid, data);
Object[][] d = new Object[1][];
Expand Down
2 changes: 2 additions & 0 deletions src/org/dhs/chrislee/imapgui/KeySelectorTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public KeySelectorTableModel(Object[][] data, String[] columnNames) {
super(data, columnNames);
}
public Class<?> getColumnClass(int columnIndex) {
if(getValueAt(0, columnIndex) == null)
return String.class;
return getValueAt(0, columnIndex).getClass();
}
@Override
Expand Down

0 comments on commit 61d88f8

Please sign in to comment.