Author: hansbak
Date: Tue Nov 21 06:51:49 2006 New Revision: 477691 URL: http://svn.apache.org/viewvc?view=rev&rev=477691 Log: add a parammeter to be able to limit the maximum size of an incoming email message (set to 1Mb) Modified: incubator/ofbiz/trunk/framework/base/config/ofbiz-containers.xml incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java Modified: incubator/ofbiz/trunk/framework/base/config/ofbiz-containers.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/base/config/ofbiz-containers.xml?view=diff&rev=477691&r1=477690&r2=477691 ============================================================================== --- incubator/ofbiz/trunk/framework/base/config/ofbiz-containers.xml (original) +++ incubator/ofbiz/trunk/framework/base/config/ofbiz-containers.xml Tue Nov 21 06:51:49 2006 @@ -55,6 +55,7 @@ <property name="run-as-user" value="system"/> <property name="poll-delay" value="300000"/> <property name="delete-mail" value="false"/> + <property name="maxSize" value="100000"/> <property name="default-listener" value="store-listener"> <property name="mail.store.protocol" value="imap"/> <property name="mail.host" value="[host]"/> Modified: incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java?view=diff&rev=477691&r1=477690&r2=477691 ============================================================================== --- incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java (original) +++ incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java Tue Nov 21 06:51:49 2006 @@ -51,6 +51,7 @@ protected LocalDispatcher dispatcher = null; protected GenericValue userLogin = null; protected long timerDelay = 300000; + protected long maxSize = 1000000; protected Timer pollTimer = null; protected boolean deleteMail = false; // whether to delete emails after fetching them. @@ -91,6 +92,7 @@ this.delegator = GenericDelegator.getGenericDelegator(delegatorName); this.dispatcher = new GenericDispatcher(dispatcherName, delegator); this.timerDelay = (long) ContainerConfig.getPropertyValue(cfg, "poll-delay", 300000); + this.maxSize = (long) ContainerConfig.getPropertyValue(cfg, "maxSize", 1000000); // maximum size in bytes // load the userLogin object String runAsUser = ContainerConfig.getPropertyValue(cfg, "run-as-user", "system"); @@ -300,16 +302,21 @@ // process each message for (int i = 0; i < messages.length; i++) { // process each un-read message - if (!messages[i].isSet(Flags.Flag.SEEN)) { - this.processMessage(messages[i], session); - if (Debug.verboseOn()) Debug.logVerbose("Message from " + UtilMisc.toListArray(messages[i].getFrom()) + " with subject [" + messages[i].getSubject() + "] has been processed." , module); - messages[i].setFlag(Flags.Flag.SEEN, true); - if (Debug.verboseOn()) Debug.logVerbose("Message [" + messages[i].getSubject() + "] is marked seen", module); - } - if (deleteMail) { - if (Debug.verboseOn()) Debug.logVerbose("Message [" + messages[i].getSubject() + "] is being deleted", module); - messages[i].setFlag(Flags.Flag.DELETED, true); - } + if (!messages[i].isSet(Flags.Flag.SEEN)) { + long messageSize = ((MimeMessage) messages[i]).getSize(); + if (messages[i] instanceof MimeMessage && messageSize >= maxSize) { + Debug.logWarning("Message from: " + ((MimeMessage)messages[i]).getFrom()[0] + "not received, to big, size:" + messageSize + " cannot be more than " + maxSize + " bytes", module); + } else { + this.processMessage(messages[i], session); + if (Debug.verboseOn()) Debug.logVerbose("Message from " + UtilMisc.toListArray(messages[i].getFrom()) + " with subject [" + messages[i].getSubject() + "] has been processed." , module); + messages[i].setFlag(Flags.Flag.SEEN, true); + if (Debug.verboseOn()) Debug.logVerbose("Message [" + messages[i].getSubject() + "] is marked seen", module); + } + } + if (deleteMail) { + if (Debug.verboseOn()) Debug.logVerbose("Message [" + messages[i].getSubject() + "] is being deleted", module); + messages[i].setFlag(Flags.Flag.DELETED, true); + } } // expunge and close the folder |
Free forum by Nabble | Edit this page |