@Test public void testGetMessageContentWithTextPlain() throws Exception { commonStubbingForGetMessageContentMethod(MimeTypes.TEXT_PLAIN); Map<String, String> messageByType = serviceSpy.getMessageByContentTypes(messageMock, CHARACTERSET); assertEquals(cmessageMock, messageByType.get(MimeTypes.TEXT_PLAIN)); commonVerifiesForGetMessageContentMethod(messageByType, MimeTypes.TEXT_PLAIN); }
protected Map<String, String> getMessageByContentTypes(Message message, String characterSet) throws Exception { Map<String, String> messageMap = new HashMap<>(); if (message.isMimeType(MimeTypes.TEXT_PLAIN)) { messageMap.put(MimeTypes.TEXT_PLAIN, MimeUtility.decodeText(message.getContent().toString())); } else if (message.isMimeType(MimeTypes.TEXT_HTML)) { messageMap.put(MimeTypes.TEXT_HTML, MimeUtility.decodeText(convertMessage(message.getContent().toString()))); } else if (message.isMimeType(MimeTypes.MULTIPART_MIXED) || message.isMimeType(MimeTypes.MULTIPART_RELATED)) { messageMap.put(MimeTypes.MULTIPART_MIXED, extractMultipartMixedMessage(message, characterSet)); } else { Object obj = message.getContent(); Multipart mpart = (Multipart) obj; for (int i = 0, n = mpart.getCount(); i < n; i++) { Part part = mpart.getBodyPart(i); if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } String disposition = part.getDisposition(); String partContentType = part.getContentType().substring(0, part.getContentType().indexOf(";")); if (disposition == null) { if (part.getContent() instanceof MimeMultipart) { MimeMultipart mm = (MimeMultipart) part.getContent(); for (int j = 0; j < mm.getCount(); j++) { if (mm.getBodyPart(j).getContent() instanceof String) { BodyPart bodyPart = mm.getBodyPart(j); if ((characterSet != null) && (characterSet.trim().length() > 0)) { String contentType = bodyPart.getHeader(CONTENT_TYPE)[0]; contentType = contentType .replace(contentType.substring(contentType.indexOf("=") + 1), characterSet); bodyPart.setHeader(CONTENT_TYPE, contentType); } String partContentType1 = bodyPart .getContentType().substring(0, bodyPart.getContentType().indexOf(";")); messageMap.put(partContentType1, MimeUtility.decodeText(bodyPart.getContent().toString())); } } } else { if ((characterSet != null) && (characterSet.trim().length() > 0)) { InputStream istream = part.getInputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(ASCIIUtility.getBytes(istream)); int count = bis.available(); byte[] bytes = new byte[count]; count = bis.read(bytes, 0, count); messageMap.put(partContentType, MimeUtility.decodeText(new String(bytes, 0, count, characterSet))); } else { messageMap.put(partContentType, MimeUtility.decodeText(part.getContent().toString())); } } } } } return messageMap; }
GetMailMessageService { protected Map<String, String> getMessageByContentTypes(Message message, String characterSet) throws Exception { Map<String, String> messageMap = new HashMap<>(); if (message.isMimeType(MimeTypes.TEXT_PLAIN)) { messageMap.put(MimeTypes.TEXT_PLAIN, MimeUtility.decodeText(message.getContent().toString())); } else if (message.isMimeType(MimeTypes.TEXT_HTML)) { messageMap.put(MimeTypes.TEXT_HTML, MimeUtility.decodeText(convertMessage(message.getContent().toString()))); } else if (message.isMimeType(MimeTypes.MULTIPART_MIXED) || message.isMimeType(MimeTypes.MULTIPART_RELATED)) { messageMap.put(MimeTypes.MULTIPART_MIXED, extractMultipartMixedMessage(message, characterSet)); } else { Object obj = message.getContent(); Multipart mpart = (Multipart) obj; for (int i = 0, n = mpart.getCount(); i < n; i++) { Part part = mpart.getBodyPart(i); if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } String disposition = part.getDisposition(); String partContentType = part.getContentType().substring(0, part.getContentType().indexOf(";")); if (disposition == null) { if (part.getContent() instanceof MimeMultipart) { MimeMultipart mm = (MimeMultipart) part.getContent(); for (int j = 0; j < mm.getCount(); j++) { if (mm.getBodyPart(j).getContent() instanceof String) { BodyPart bodyPart = mm.getBodyPart(j); if ((characterSet != null) && (characterSet.trim().length() > 0)) { String contentType = bodyPart.getHeader(CONTENT_TYPE)[0]; contentType = contentType .replace(contentType.substring(contentType.indexOf("=") + 1), characterSet); bodyPart.setHeader(CONTENT_TYPE, contentType); } String partContentType1 = bodyPart .getContentType().substring(0, bodyPart.getContentType().indexOf(";")); messageMap.put(partContentType1, MimeUtility.decodeText(bodyPart.getContent().toString())); } } } else { if ((characterSet != null) && (characterSet.trim().length() > 0)) { InputStream istream = part.getInputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(ASCIIUtility.getBytes(istream)); int count = bis.available(); byte[] bytes = new byte[count]; count = bis.read(bytes, 0, count); messageMap.put(partContentType, MimeUtility.decodeText(new String(bytes, 0, count, characterSet))); } else { messageMap.put(partContentType, MimeUtility.decodeText(part.getContent().toString())); } } } } } return messageMap; } }
GetMailMessageService { protected Map<String, String> getMessageByContentTypes(Message message, String characterSet) throws Exception { Map<String, String> messageMap = new HashMap<>(); if (message.isMimeType(MimeTypes.TEXT_PLAIN)) { messageMap.put(MimeTypes.TEXT_PLAIN, MimeUtility.decodeText(message.getContent().toString())); } else if (message.isMimeType(MimeTypes.TEXT_HTML)) { messageMap.put(MimeTypes.TEXT_HTML, MimeUtility.decodeText(convertMessage(message.getContent().toString()))); } else if (message.isMimeType(MimeTypes.MULTIPART_MIXED) || message.isMimeType(MimeTypes.MULTIPART_RELATED)) { messageMap.put(MimeTypes.MULTIPART_MIXED, extractMultipartMixedMessage(message, characterSet)); } else { Object obj = message.getContent(); Multipart mpart = (Multipart) obj; for (int i = 0, n = mpart.getCount(); i < n; i++) { Part part = mpart.getBodyPart(i); if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } String disposition = part.getDisposition(); String partContentType = part.getContentType().substring(0, part.getContentType().indexOf(";")); if (disposition == null) { if (part.getContent() instanceof MimeMultipart) { MimeMultipart mm = (MimeMultipart) part.getContent(); for (int j = 0; j < mm.getCount(); j++) { if (mm.getBodyPart(j).getContent() instanceof String) { BodyPart bodyPart = mm.getBodyPart(j); if ((characterSet != null) && (characterSet.trim().length() > 0)) { String contentType = bodyPart.getHeader(CONTENT_TYPE)[0]; contentType = contentType .replace(contentType.substring(contentType.indexOf("=") + 1), characterSet); bodyPart.setHeader(CONTENT_TYPE, contentType); } String partContentType1 = bodyPart .getContentType().substring(0, bodyPart.getContentType().indexOf(";")); messageMap.put(partContentType1, MimeUtility.decodeText(bodyPart.getContent().toString())); } } } else { if ((characterSet != null) && (characterSet.trim().length() > 0)) { InputStream istream = part.getInputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(ASCIIUtility.getBytes(istream)); int count = bis.available(); byte[] bytes = new byte[count]; count = bis.read(bytes, 0, count); messageMap.put(partContentType, MimeUtility.decodeText(new String(bytes, 0, count, characterSet))); } else { messageMap.put(partContentType, MimeUtility.decodeText(part.getContent().toString())); } } } } } return messageMap; }  }
GetMailMessageService { protected Map<String, String> getMessageByContentTypes(Message message, String characterSet) throws Exception { Map<String, String> messageMap = new HashMap<>(); if (message.isMimeType(MimeTypes.TEXT_PLAIN)) { messageMap.put(MimeTypes.TEXT_PLAIN, MimeUtility.decodeText(message.getContent().toString())); } else if (message.isMimeType(MimeTypes.TEXT_HTML)) { messageMap.put(MimeTypes.TEXT_HTML, MimeUtility.decodeText(convertMessage(message.getContent().toString()))); } else if (message.isMimeType(MimeTypes.MULTIPART_MIXED) || message.isMimeType(MimeTypes.MULTIPART_RELATED)) { messageMap.put(MimeTypes.MULTIPART_MIXED, extractMultipartMixedMessage(message, characterSet)); } else { Object obj = message.getContent(); Multipart mpart = (Multipart) obj; for (int i = 0, n = mpart.getCount(); i < n; i++) { Part part = mpart.getBodyPart(i); if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } String disposition = part.getDisposition(); String partContentType = part.getContentType().substring(0, part.getContentType().indexOf(";")); if (disposition == null) { if (part.getContent() instanceof MimeMultipart) { MimeMultipart mm = (MimeMultipart) part.getContent(); for (int j = 0; j < mm.getCount(); j++) { if (mm.getBodyPart(j).getContent() instanceof String) { BodyPart bodyPart = mm.getBodyPart(j); if ((characterSet != null) && (characterSet.trim().length() > 0)) { String contentType = bodyPart.getHeader(CONTENT_TYPE)[0]; contentType = contentType .replace(contentType.substring(contentType.indexOf("=") + 1), characterSet); bodyPart.setHeader(CONTENT_TYPE, contentType); } String partContentType1 = bodyPart .getContentType().substring(0, bodyPart.getContentType().indexOf(";")); messageMap.put(partContentType1, MimeUtility.decodeText(bodyPart.getContent().toString())); } } } else { if ((characterSet != null) && (characterSet.trim().length() > 0)) { InputStream istream = part.getInputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(ASCIIUtility.getBytes(istream)); int count = bis.available(); byte[] bytes = new byte[count]; count = bis.read(bytes, 0, count); messageMap.put(partContentType, MimeUtility.decodeText(new String(bytes, 0, count, characterSet))); } else { messageMap.put(partContentType, MimeUtility.decodeText(part.getContent().toString())); } } } } } return messageMap; }  Map<String, String> execute(GetMailMessageInput getMailMessageInput); }
GetMailMessageService { protected Map<String, String> getMessageByContentTypes(Message message, String characterSet) throws Exception { Map<String, String> messageMap = new HashMap<>(); if (message.isMimeType(MimeTypes.TEXT_PLAIN)) { messageMap.put(MimeTypes.TEXT_PLAIN, MimeUtility.decodeText(message.getContent().toString())); } else if (message.isMimeType(MimeTypes.TEXT_HTML)) { messageMap.put(MimeTypes.TEXT_HTML, MimeUtility.decodeText(convertMessage(message.getContent().toString()))); } else if (message.isMimeType(MimeTypes.MULTIPART_MIXED) || message.isMimeType(MimeTypes.MULTIPART_RELATED)) { messageMap.put(MimeTypes.MULTIPART_MIXED, extractMultipartMixedMessage(message, characterSet)); } else { Object obj = message.getContent(); Multipart mpart = (Multipart) obj; for (int i = 0, n = mpart.getCount(); i < n; i++) { Part part = mpart.getBodyPart(i); if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } String disposition = part.getDisposition(); String partContentType = part.getContentType().substring(0, part.getContentType().indexOf(";")); if (disposition == null) { if (part.getContent() instanceof MimeMultipart) { MimeMultipart mm = (MimeMultipart) part.getContent(); for (int j = 0; j < mm.getCount(); j++) { if (mm.getBodyPart(j).getContent() instanceof String) { BodyPart bodyPart = mm.getBodyPart(j); if ((characterSet != null) && (characterSet.trim().length() > 0)) { String contentType = bodyPart.getHeader(CONTENT_TYPE)[0]; contentType = contentType .replace(contentType.substring(contentType.indexOf("=") + 1), characterSet); bodyPart.setHeader(CONTENT_TYPE, contentType); } String partContentType1 = bodyPart .getContentType().substring(0, bodyPart.getContentType().indexOf(";")); messageMap.put(partContentType1, MimeUtility.decodeText(bodyPart.getContent().toString())); } } } else { if ((characterSet != null) && (characterSet.trim().length() > 0)) { InputStream istream = part.getInputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(ASCIIUtility.getBytes(istream)); int count = bis.available(); byte[] bytes = new byte[count]; count = bis.read(bytes, 0, count); messageMap.put(partContentType, MimeUtility.decodeText(new String(bytes, 0, count, characterSet))); } else { messageMap.put(partContentType, MimeUtility.decodeText(part.getContent().toString())); } } } } } return messageMap; }  Map<String, String> execute(GetMailMessageInput getMailMessageInput);  }