/** * Returns <code>true</code> if the email is unread (incoming mail), or * if it has not been sent yet (outgoing mail).<br/> * The default is <code>true</code>. */ public boolean isUnread() { return "true".equalsIgnoreCase(getProperty(PROPERTY_UNREAD)); }
/** * Returns <code>true</code> if the email has recently arrived in its * parent folder.<br/> * The default is <code>false</code>. */ public boolean isRecent() { return "true".equalsIgnoreCase(getProperty(PROPERTY_RECENT)); }
public boolean isReplied() { String repliedStr = getProperty(PROPERTY_REPLIED); return "true".equals(repliedStr); }
public boolean isDeleted() { String deletedStr = getProperty(PROPERTY_DELETED); return "true".equals(deletedStr); }
/** * Tests if the email has been delivered to a given destination. * @param destIndex the destination index in the property key, e.g. 5 for "destination5" */ private boolean isDelivered(int destIndex) { int packetIndex = 0; while (true) { String packetDeliveredStr = getProperty(PROPERTY_DESTINATION + destIndex + "." + PACKET + packetIndex + "." + DELETED_FROM_DHT); if (packetDeliveredStr == null) return true; boolean packetDelivered = "true".equalsIgnoreCase(packetDeliveredStr); if (!packetDelivered) return false; packetIndex++; } }
private int getDestinationIndex(EmailDestination destination) { int destIndex = 0; while (true) { String value = getProperty(PROPERTY_DESTINATION + destIndex); if (value==null || destination.toBase64().equals(value)) return destIndex; destIndex++; } }
private int getPacketIndex(int destIndex, Hash dhtKey) { int pktIndex = 0; while (true) { String value = getProperty(PROPERTY_DESTINATION + destIndex + "." + PACKET + pktIndex + "." + DHT_KEY); if (value==null || dhtKey.toBase64().equals(value)) return pktIndex; pktIndex++; } }
private int getNumDeliveredPackets() { int numUndelivered = 0; for (Object property: keySet()) if (property instanceof String) { String delFlagProperty = (String)property; if (delFlagProperty.matches(PROPERTY_DESTINATION + ".*" + DELETED_FROM_DHT) && "true".equals(getProperty(delFlagProperty))) numUndelivered++; } return numUndelivered; }
/** Returns the number of recipients who haven't picked up all email packets. */ public int getNumUndeliveredRecipients() { int destIndex = 0; int numUndelivered = 0; while (true) { String value = getProperty(PROPERTY_DESTINATION + destIndex); if (value == null) break; if (!isDelivered(destIndex)) numUndelivered++; destIndex++; } return numUndelivered; }
/** * Returns the time and date the email was received. If no received * date has been set, or if it is invalid, <code>null</code> is returned. */ public Date getReceivedDate() { String dateStr = getProperty(PROPERTY_RECEIVED_DATE); if (dateStr == null) return null; else { try { long milliseconds = Long.valueOf(dateStr); return new Date(milliseconds); } catch (NumberFormatException e) { log.error("Invalid received date (should be a whole number): <" + dateStr + ">"); return null; } } }
public void setPacketDelivered(Hash dhtKey, boolean delivered) { String dhtKeyStr = dhtKey.toBase64(); for (Object property: keySet()) if (property instanceof String) { String propertyStr = (String)property; if (propertyStr.matches(PROPERTY_DESTINATION + ".*" + DHT_KEY) && dhtKeyStr.equals(getProperty(propertyStr))) { String deletedProperty = propertyStr.replace(DHT_KEY, DELETED_FROM_DHT); setProperty(deletedProperty, delivered ? "true" : "false"); } } }
/** Returns the DHT keys of all email packets which haven't been deleted from the DHT */ public Collection<PacketInfo> getUndeliveredPacketKeys() { Collection<PacketInfo> packets = new ArrayList<PacketInfo>(); for (Object property: keySet()) if (property instanceof String) { String delFlagProperty = (String)property; if (delFlagProperty.matches(PROPERTY_DESTINATION + ".*" + DELETED_FROM_DHT) && "false".equals(getProperty(delFlagProperty))) { String baseProperty = delFlagProperty.replace(DELETED_FROM_DHT, ""); String dhtKeyProperty = baseProperty + DHT_KEY; String dhtKeyStr = getProperty(dhtKeyProperty); String delVerifProperty = baseProperty + DELETE_VERIFICATION_HASH; String delVerifStr = getProperty(delVerifProperty); try { Hash dhtKey = Util.createHash(dhtKeyStr); Hash delVerifHash = Util.createHash(delVerifStr); packets.add(new PacketInfo(dhtKey, delVerifHash)); } catch (DataFormatException e) { log.error("Invalid DHT key or verification hash in email metadata for property key " + baseProperty, e); } } } return packets; }
/** * Returns the date and time the email was submitted by the user, or <code>null</code> * if the value cannot be parsed. */ public Date getCreateTime() { String dateStr = getProperty(PROPERTY_CREATE_TIME); Date createTime; try { createTime = new MailDateFormat().parse(dateStr); } catch (ParseException e) { log.error("Can't parse create time.", e); createTime = null; } return createTime; }
public Hash getDeleteVerificationHash(EmailDestination destination, Hash dhtKey) { int destIndex = getDestinationIndex(destination); int packetIndex = getPacketIndex(destIndex, dhtKey); String hashStr = getProperty(PROPERTY_DESTINATION + destIndex + "." + PACKET + packetIndex + "." + DELETE_VERIFICATION_HASH); try { return Util.createHash(hashStr); } catch (DataFormatException e) { log.error("Invalid delete verification hash: <" + hashStr + ">", e); return null; } }