📄 messageprocessor.java
字号:
/** * Sets the userUndefined. * @param userUndefined The userUndefined to set */ protected void setUserUndefined(boolean userUndefined) { fieldUserUndefined = userUndefined; } /** * Adds the mail attributes to a <code>Mail</code>. * @param aMail a Mail instance */ protected void addMailAttributes(Mail aMail) throws MessagingException { aMail.setAttribute( getAttributePrefix() + "taskName", getFetchTaskName()); aMail.setAttribute( getAttributePrefix() + "folderName", getMessageIn().getFolder().getFullName()); if (isRemoteRecipient()) aMail.setAttribute( getAttributePrefix() + "isRemoteRecipient", null); if (isUserUndefined()) aMail.setAttribute(getAttributePrefix() + "isUserUndefined", null); if (isBlacklistedRecipient()) aMail.setAttribute( getAttributePrefix() + "isBlacklistedRecipient", null); if (isRecipientNotFound()) aMail.setAttribute( getAttributePrefix() + "isRecipientNotFound", null); if (isMaxMessageSizeExceeded().booleanValue()) aMail.setAttribute( getAttributePrefix() + "isMaxMessageSizeExceeded", new Integer(getMessageIn().getSize()).toString()); if (isRemoteReceivedHeaderInvalid().booleanValue()) aMail.setAttribute( getAttributePrefix() + "isRemoteReceivedHeaderInvalid", null); } /** * Adds any required error messages to a <code>Mail</code>. * @param aMail a Mail instance */ protected void addErrorMessages(Mail mail) throws MessagingException { if (isMaxMessageSizeExceeded().booleanValue()) { StringBuffer msgBuffer = new StringBuffer("550 - Rejected - This message has been rejected as the message size of "); msgBuffer.append(getMessageIn().getSize() * 1000 / 1024 / 1000f); msgBuffer.append("KB exceeds the maximum permitted size of "); msgBuffer.append(getMaxMessageSizeLimit() / 1024); msgBuffer.append("KB."); mail.setErrorMessage(msgBuffer.toString()); } } /** * Sets the Blacklisted. * @param blacklisted The blacklisted to set */ protected void setBlacklistedRecipient(boolean blacklisted) { fieldBlacklistedRecipient = blacklisted; } /** * Returns the recipientNotFound. * @return boolean */ protected boolean isRecipientNotFound() { return fieldRecipientNotFound; } /** * Sets the recipientNotFound. * @param recipientNotFound The recipientNotFound to set */ protected void setRecipientNotFound(boolean recipientNotFound) { fieldRecipientNotFound = recipientNotFound; } /** * Returns the remoteDomain, lazily initialised as required. * @return String */ protected String getRemoteDomain() throws MessagingException { String remoteDomain; if (null == (remoteDomain = getRemoteDomainBasic())) { updateRemoteDomain(); return getRemoteDomain(); } return remoteDomain; } /** * Returns the remoteDomain. * @return String */ private String getRemoteDomainBasic() { return fieldRemoteDomain; } /** * Sets the remoteDomain. * @param remoteDomain The remoteDomain to set */ protected void setRemoteDomain(String remoteDomain) { fieldRemoteDomain = remoteDomain; } /** * Updates the remoteDomain. */ protected void updateRemoteDomain() throws MessagingException { setRemoteDomain(computeRemoteDomain()); } /** * Answer the IP Address of the remote server for the message being * processed. * @return String * @throws MessagingException * @throws UnknownHostException */ protected String computeRemoteAddress() throws MessagingException, UnknownHostException { String domain = getRemoteDomain(); String address = null; String validatedAddress = null; int ipAddressStart = domain.indexOf('['); int ipAddressEnd = -1; if (ipAddressStart > -1) ipAddressEnd = domain.indexOf(']', ipAddressStart); if (ipAddressEnd > -1) address = domain.substring(ipAddressStart + 1, ipAddressEnd); else { int hostNameEnd = domain.indexOf(' '); if (hostNameEnd == -1) hostNameEnd = domain.length(); address = domain.substring(0, hostNameEnd); } validatedAddress = org.apache.james.dnsserver.DNSServer.getByName(address).getHostAddress(); return validatedAddress; } /** * Answer the Canonical host name of the remote server for the message * being processed. * @return String * @throws MessagingException * @throws UnknownHostException */ protected String computeRemoteHostName() throws MessagingException, UnknownHostException { // These shenanigans are required to get the fully qualified // hostname prior to JDK 1.4 in which get getCanonicalHostName() // does the job for us InetAddress addr1 = org.apache.james.dnsserver.DNSServer.getByName(getRemoteAddress()); InetAddress addr2 = org.apache.james.dnsserver.DNSServer.getByName(addr1.getHostAddress()); return addr2.getHostName(); } /** * Returns the remoteAddress, lazily initialised as required. * @return String */ protected String getRemoteAddress() throws MessagingException, UnknownHostException { String remoteAddress; if (null == (remoteAddress = getRemoteAddressBasic())) { updateRemoteAddress(); return getRemoteAddress(); } return remoteAddress; } /** * Returns the remoteAddress. * @return String */ private String getRemoteAddressBasic() { return fieldRemoteAddress; } /** * Returns the remoteHostName, lazily initialised as required. * @return String */ protected String getRemoteHostName() throws MessagingException, UnknownHostException { String remoteHostName; if (null == (remoteHostName = getRemoteHostNameBasic())) { updateRemoteHostName(); return getRemoteHostName(); } return remoteHostName; } /** * Returns the remoteHostName. * @return String */ private String getRemoteHostNameBasic() { return fieldRemoteHostName; } /** * Sets the remoteAddress. * @param remoteAddress The remoteAddress to set */ protected void setRemoteAddress(String remoteAddress) { fieldRemoteAddress = remoteAddress; } /** * Updates the remoteAddress. */ protected void updateRemoteAddress() throws MessagingException, UnknownHostException { setRemoteAddress(computeRemoteAddress()); } /** * Sets the remoteHostName. * @param remoteHostName The remoteHostName to set */ protected void setRemoteHostName(String remoteHostName) { fieldRemoteHostName = remoteHostName; } /** * Updates the remoteHostName. */ protected void updateRemoteHostName() throws MessagingException, UnknownHostException { setRemoteHostName(computeRemoteHostName()); } /** * Returns the rFC2822RECEIVEDHeaderFields. * @return String */ public static String getRFC2822RECEIVEDHeaderFields() { return fieldRFC2822RECEIVEDHeaderFields; } /** * Returns the maxMessageSizeExceeded, lazily initialised as required. * @return Boolean */ protected Boolean isMaxMessageSizeExceeded() throws MessagingException { Boolean isMaxMessageSizeExceeded = null; if (null == (isMaxMessageSizeExceeded = isMaxMessageSizeExceededBasic())) { updateMaxMessageSizeExceeded(); return isMaxMessageSizeExceeded(); } return isMaxMessageSizeExceeded; } /** * Refreshes the maxMessageSizeExceeded. */ protected void updateMaxMessageSizeExceeded() throws MessagingException { setMaxMessageSizeExceeded(computeMaxMessageSizeExceeded()); } /** * Compute the maxMessageSizeExceeded. * @return Boolean */ protected Boolean computeMaxMessageSizeExceeded() throws MessagingException { if (0 == getMaxMessageSizeLimit()) return Boolean.FALSE; return new Boolean(getMessageIn().getSize() > getMaxMessageSizeLimit()); } /** * Returns the maxMessageSizeExceeded. * @return Boolean */ private Boolean isMaxMessageSizeExceededBasic() { return fieldMaxMessageSizeExceeded; } /** * Sets the maxMessageSizeExceeded. * @param maxMessageSizeExceeded The maxMessageSizeExceeded to set */ protected void setMaxMessageSizeExceeded(Boolean maxMessageSizeExceeded) { fieldMaxMessageSizeExceeded = maxMessageSizeExceeded; } /** * Returns the remoteReceivedHeaderInvalid, lazily initialised. * @return Boolean */ protected Boolean isRemoteReceivedHeaderInvalid() throws MessagingException { Boolean isInvalid = null; if (null == (isInvalid = isRemoteReceivedHeaderInvalidBasic())) { updateRemoteReceivedHeaderInvalid(); return isRemoteReceivedHeaderInvalid(); } return isInvalid; } /** * Computes the remoteReceivedHeaderInvalid. * @return Boolean */ protected Boolean computeRemoteReceivedHeaderInvalid() throws MessagingException { Boolean isInvalid = Boolean.FALSE; try { getRemoteAddress(); } catch (UnknownHostException e) { isInvalid = Boolean.TRUE; } return isInvalid; } /** * Returns the remoteReceivedHeaderInvalid. * @return Boolean */ private Boolean isRemoteReceivedHeaderInvalidBasic() { return fieldRemoteReceivedHeaderInvalid; } /** * Sets the remoteReceivedHeaderInvalid. * @param remoteReceivedHeaderInvalid The remoteReceivedHeaderInvalid to set */ protected void setRemoteReceivedHeaderInvalid(Boolean remoteReceivedHeaderInvalid) { fieldRemoteReceivedHeaderInvalid = remoteReceivedHeaderInvalid; } /** * Updates the remoteReceivedHeaderInvalid. */ protected void updateRemoteReceivedHeaderInvalid() throws MessagingException { setRemoteReceivedHeaderInvalid(computeRemoteReceivedHeaderInvalid()); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -