Author: jaz
Date: Wed May 13 03:05:00 2009 New Revision: 774178 URL: http://svn.apache.org/viewvc?rev=774178&view=rev Log: more improvements to the message wrapper logic for getting attachments and reading multipart messages; added methods to get headers; mail container now marks messages which are too big to process (the max size setting) as read (but never deleted) so they are not always being checked but remain in the mailbox for human review Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/MimeMessageWrapper.java Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java?rev=774178&r1=774177&r2=774178&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java Wed May 13 03:05:00 2009 @@ -305,17 +305,22 @@ long messageSize = message.getSize(); if (message instanceof MimeMessage && messageSize >= maxSize) { Debug.logWarning("Message from: " + message.getFrom()[0] + "not received, too big, size:" + messageSize + " cannot be more than " + maxSize + " bytes", module); + + // set the message as read so it doesn't continue to try to process; but don't delete it + message.setFlag(Flags.Flag.SEEN, true); } else { this.processMessage(message, session); if (Debug.verboseOn()) Debug.logVerbose("Message from " + UtilMisc.toListArray(message.getFrom()) + " with subject [" + message.getSubject() + "] has been processed." , module); message.setFlag(Flags.Flag.SEEN, true); if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is marked seen", module); + + // delete the message after processing + if (deleteMail) { + if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is being deleted", module); + message.setFlag(Flags.Flag.DELETED, true); + } } - } - if (deleteMail) { - if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is being deleted", module); - message.setFlag(Flags.Flag.DELETED, true); - } + } } // expunge and close the folder Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/MimeMessageWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/MimeMessageWrapper.java?rev=774178&r1=774177&r2=774178&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/MimeMessageWrapper.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/MimeMessageWrapper.java Wed May 13 03:05:00 2009 @@ -122,6 +122,24 @@ return message; } + public String getFirstHeader(String header) { + String[] headers = getHeader(header); + if (headers != null && headers.length > 0) { + return headers[0]; + } else { + return null; + } + } + public String[] getHeader(String header) { + MimeMessage message = getMessage(); + try { + return message.getHeader(header); + } catch (MessagingException e) { + Debug.logError(e, module); + return null; + } + } + public Address[] getFrom() { MimeMessage message = getMessage(); try { @@ -235,14 +253,16 @@ String idx = Integer.toString(i); if (subPartCount > 0) { for (int si = 0; si < subPartCount; si++) { - String sidx = idx + "." + Integer.toString(si); - if (getPartDisposition(sidx) != null && getPartDisposition(sidx).equals(Part.ATTACHMENT)) { - attachments.add(sidx); + String sidx = idx + "." + Integer.toString(si); + if (getPartDisposition(sidx) != null && (getPartDisposition(sidx).equals(Part.ATTACHMENT) || + getPartDisposition(sidx).equals(Part.INLINE))) { + attachments.add(sidx); } } - } else { - if (getPartDisposition(idx) != null && getPartDisposition(idx).equals(Part.ATTACHMENT)) { - attachments.add(idx); + } else { + if (getPartDisposition(idx) != null && (getPartDisposition(idx).equals(Part.ATTACHMENT) || + getPartDisposition(idx).equals(Part.INLINE))) { + attachments.add(idx); } } } @@ -268,8 +288,10 @@ if (subPartCount > 0) { for (int si = 0; si < subPartCount; si++) { String sidx = idx + "." + Integer.toString(si); - if (getPartDisposition(sidx) == null || getPartDisposition(sidx).equals(Part.INLINE)) { - body.append(getPartText(sidx)).append("\n"); + if (getPartContentType(sidx) != null && getPartContentType(sidx).toLowerCase().startsWith("text")) { + if (getPartDisposition(sidx) == null || getPartDisposition(sidx).equals(Part.INLINE)) { + body.append(getPartText(sidx)).append("\n"); + } } } } else { @@ -285,6 +307,36 @@ } } + public String getMessageBodyContentType() { + String contentType = getContentType(); + if (contentType != null && contentType.toLowerCase().startsWith("text")) { + return contentType; + } else { + for (int i = 0; i < getMainPartCount(); i++) { + int subPartCount = getSubPartCount(i); + String idx = Integer.toString(i); + if (subPartCount > 0) { + for (int si = 0; si < subPartCount; si++) { + String sidx = idx + "." + Integer.toString(si); + if (getPartContentType(sidx) != null && getPartContentType(sidx).toLowerCase().startsWith("text")) { + if (getPartDisposition(sidx) == null || getPartDisposition(sidx).equals(Part.INLINE)) { + return getPartContentType(sidx); + } + } + } + } else { + if (getPartContentType(idx) != null && getPartContentType(idx).toLowerCase().startsWith("text")) { + // make sure the part isn't an attachment + if (getPartDisposition(idx) == null || getPartDisposition(idx).equals(Part.INLINE)) { + return getPartContentType(idx); + } + } + } + } + } + return "text/html"; + } + public String getMessageRawText() { MimeMessage message = getMessage(); try { @@ -482,7 +534,7 @@ byte[] buffer = new byte[4096]; try { for (int n; (n = stream.read(buffer)) != -1;) { - baos.write(n); + baos.write(buffer, 0, n); } } catch (IOException e) { Debug.logError(e, module); |
Free forum by Nabble | Edit this page |