public void setHashCash(HashCash hashCash) throws MessagingException { setHeader("X-HashCash", hashCash.toString()); }
/** * Update the Message-ID header. This method is called * by the <code>updateHeaders</code>. The algorithm for * choosing a Message-ID is overridden on Android because * the default calls <code>InetAddress.getLocalHost()</code> * which triggers a <code>NetworkOnMainThreadException</code>. */ protected void updateMessageID() throws MessagingException { if (SystemVersion.isAndroid()) { String suffix = "droidjavamailuser@localhost"; StringBuffer s = new StringBuffer(); // Unique string is <hashcode>.<id>.<currentTime>.JavaMail.<suffix> s.append(s.hashCode()).append('.'). append(androidUniqueID.getAndIncrement()).append('.'). append(System.currentTimeMillis()).append('.'). append("JavaMail."). append(suffix); setHeader("Message-ID", "<" + s.toString() + ">"); } else { super.updateMessageID(); } }
/** * Verifies the signature and sets the <code>SIGNATURE_VALID_HEADER</code> * header field accordingly. */ public void setSignatureFlag() { try { removeHeader(SIGNATURE_VALID_HEADER); // remove the signature validity flag before verifying boolean valid = verifySignature(); setHeader(SIGNATURE_VALID_HEADER, String.valueOf(valid)); } catch (MessagingException e) { log.error("Cannot get header field: " + SIGNATURE_VALID_HEADER, e); } }
/** * Removes all headers that are not on the whitelist, and initializes some * basic header fields.<br/> * Called by {@link #saveChanges()}, see JavaMail JavaDoc. * @throws MessagingException */ @Override public void updateHeaders() throws MessagingException { super.updateHeaders(); scrubHeaders(); removeRecipientNames(); // Depending on includeSendTime, set the send time or remove the send time field if (includeSendTime) { // Ensure the "Date" field is set in UTC time, using the English locale. MailDateFormat formatter = new MailDateFormat(); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); // always use UTC for outgoing mail if (getSentDate() == null) setHeader("Date", formatter.format(new Date())); else setHeader("Date", formatter.format(getSentDate())); } else removeHeader("Date"); }
saveChanges(); if (bccToKeep!=null && isBCC(bccToKeep)) setHeader("BCC", bccToKeep); // set bccToKeep and remove any other existing BCC addresses else removeHeader("BCC");
} finally { try { setHeader(SIGNATURE_HEADER, signatureHeader); } catch (MessagingException e) { log.error("Cannot set signature header field.", e);
/** * Creates a digital signature of the email and stores it in the * <code>SIGNATURE_HEADER</code> header field. It also removes the * <code>SIGNATURE_VALID_HEADER</code> header. If there is a signature * already, it is replaced.<br/> * The signature is computed over the stream representation of the * email, minus the signature header if it is present.<br/> * The signature includes the ID number of the {@link CryptoImplementation} * used (signature lengths can be different for the same algorithm). * @param senderIdentity * @param keyUpdateHandler Needed for updating the signature key after signing (see {@link CryptoImplementation#sign(byte[], PrivateKey, KeyUpdateHandler)}) * @throws MessagingException * @throws GeneralSecurityException * @throws PasswordException */ public void sign(EmailIdentity senderIdentity, KeyUpdateHandler keyUpdateHandler) throws MessagingException, GeneralSecurityException, PasswordException { removeHeader(SIGNATURE_HEADER); // make sure there is no existing signature which would make the new signature invalid removeHeader(SIGNATURE_VALID_HEADER); // remove the signature validity flag before signing CryptoImplementation cryptoImpl = senderIdentity.getCryptoImpl(); PrivateKey privateSigningKey = senderIdentity.getPrivateSigningKey(); byte[] signature = cryptoImpl.sign(toByteArray(), privateSigningKey, keyUpdateHandler); String foldedSignature = foldSignature(cryptoImpl.getId() + "_" + Base64.encode(signature)); setHeader(SIGNATURE_HEADER, foldedSignature); }