Author: hansbak
Date: Mon Oct 13 00:13:55 2008 New Revision: 703930 URL: http://svn.apache.org/viewvc?rev=703930&view=rev Log: make the recieval of attachments possible with html messages Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailWorker.java Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java?rev=703930&r1=703929&r2=703930&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java Mon Oct 13 00:13:55 2008 @@ -850,12 +850,13 @@ commEventMap.put("roleTypeIdTo", "_NA_"); // get the content(type) part + Object messageContent = message.getContent(); if (contentType.startsWith("text")) { - commEventMap.put("content", message.getContent()); + commEventMap.put("content", messageContent); commEventMap.put("contentMimeTypeId", contentType); - } else if (contentType.startsWith("multipart") || contentType.startsWith("Multipart")) { + } else if (messageContent instanceof Multipart) { contentIndex = ""; - commEventMap = addMessageBody(commEventMap, (Multipart) message.getContent()); + commEventMap = addMessageBody(commEventMap, (Multipart) messageContent); } // check for for a reply to communication event (using in-reply-to the parent messageID) @@ -956,9 +957,9 @@ result = dispatcher.runSync("createCommunicationEvent", commEventMap); communicationEventId = (String)result.get("communicationEventId"); - // store attachments - if (contentType.startsWith("multipart") || contentType.startsWith("Multipart")) { - int attachmentCount = EmailWorker.addAttachmentsToCommEvent(message, communicationEventId, dispatcher, userLogin); + if (messageContent instanceof Multipart) { + Debug.logInfo("===message has attachments=====", module); + int attachmentCount = EmailWorker.addAttachmentsToCommEvent((Multipart) messageContent, subject, communicationEventId, dispatcher, userLogin); if (Debug.infoOn()) Debug.logInfo(attachmentCount + " attachments added to CommunicationEvent:" + communicationEventId,module); } Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailWorker.java?rev=703930&r1=703929&r2=703930&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailWorker.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailWorker.java Mon Oct 13 00:13:55 2008 @@ -46,21 +46,19 @@ return fieldValue; } - public static int addAttachmentsToCommEvent(MimeMessage message, String communicationEventId, LocalDispatcher dispatcher, GenericValue userLogin) + public static int addAttachmentsToCommEvent(Multipart messageContent, String subject, String communicationEventId, LocalDispatcher dispatcher, GenericValue userLogin) throws MessagingException, IOException, GenericServiceException { Map commEventMap = FastMap.newInstance(); commEventMap.put("communicationEventId", communicationEventId); commEventMap.put("contentTypeId", "DOCUMENT"); commEventMap.put("mimeTypeId", "text/html"); commEventMap.put("userLogin", userLogin); - String subject = message.getSubject(); if (subject != null && subject.length() > 80) { subject = subject.substring(0,80); // make sure not too big for database field. (20 characters for filename) } currentIndex = ""; attachmentCount = 0; - return addMultipartAttachementToComm((Multipart)message.getContent(), commEventMap, subject, dispatcher, userLogin); - + return addMultipartAttachementToComm(messageContent, commEventMap, subject, dispatcher, userLogin); } private static String currentIndex = ""; private static int attachmentCount = 0; @@ -68,29 +66,35 @@ throws MessagingException, IOException, GenericServiceException { try { int multipartCount = multipart.getCount(); + // Debug.logInfo(currentIndex + "====number of attachments: " + multipartCount, module); for (int i=0; i < multipartCount; i++) { + // Debug.logInfo(currentIndex + "====processing attachment: " + i, module); Part part = multipart.getBodyPart(i); String thisContentTypeRaw = part.getContentType(); + // Debug.logInfo("====thisContentTypeRaw: " + thisContentTypeRaw, module); int idx2 = thisContentTypeRaw.indexOf(";"); if (idx2 == -1) idx2 = thisContentTypeRaw.length(); String thisContentType = thisContentTypeRaw.substring(0, idx2); String disposition = part.getDisposition(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - if (thisContentType.startsWith("multipart") || thisContentType.startsWith("Multipart")) { + if (part instanceof Multipart) { currentIndex = currentIndex.concat("." + i); - return addMultipartAttachementToComm((Multipart) part.getContent(), commEventMap, subject, dispatcher, userLogin); + // Debug.logInfo("=====attachment contain attachment, index:" + currentIndex, module); + return addMultipartAttachementToComm((Multipart) part.getContent(), commEventMap, subject, dispatcher, userLogin); } - + // Debug.logInfo("=====attachment not contains attachment, index:" + currentIndex, module); + // Debug.logInfo("=====check for currentIndex(" + currentIndex + ") against master contentIndex(" + EmailServices.contentIndex + ")", module); if(currentIndex.concat("." + i).equals(EmailServices.contentIndex)) continue; // The first test should not pass, because if it exists, it should be the bodyContentIndex part - if (((disposition == null) && (i == 0) && thisContentType.startsWith("text")) + // Debug.logInfo("====check for disposition: " + disposition + " contentType: '" + thisContentType + "' variable i:" + i, module); + if ((disposition == null && thisContentType.startsWith("text")) || ((disposition != null) && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE)) ) ) { - String attFileName = part.getFileName(); + String attFileName = part.getFileName(); + Debug.logInfo("===processing attachment: " + attFileName, module); if (!UtilValidate.isEmpty(attFileName)) { commEventMap.put("contentName", attFileName); commEventMap.put("description", subject + "-" + attachmentCount); |
Free forum by Nabble | Edit this page |