@Test public void testGetAttachedFileNamesWhereContentIsNotMultiPart() throws Exception { doReturn(objectMock).when(partMock).getContent(); String testFileName = "testFileName"; doReturn(testFileName).when(partMock).getFileName(); doReturn(inputStreamMock).when(partMock).getInputStream(); serviceSpy.input = inputBuilder.build(); String fileNames = serviceSpy.getAttachedFileNames(partMock); assertEquals(testFileName, fileNames); }
protected String getAttachedFileNames(Part part) throws Exception { String fileNames = StringUtils.EMPTY; Object content = part.getContent(); if (!(content instanceof Multipart)) { if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } if (part.getFileName() != null && !part.getFileName().equals(StringUtils.EMPTY) && part.getInputStream() != null) { String fileName = part.getFileName(); if (fileName.indexOf('?') == -1) { return fileName; } return fileName.substring(fileName.indexOf("=?"), fileName.length() - ((new StringBuilder(fileName)).reverse()).indexOf("=?")); } } else { Multipart mpart = (Multipart) content; for (int i = 0, n = mpart.getCount(); i < n; i++) { if (!StringUtils.EMPTY.equals(fileNames)) { fileNames += ","; } fileNames += getAttachedFileNames(mpart.getBodyPart(i)); } } return fileNames; }
GetMailMessageService { protected String getAttachedFileNames(Part part) throws Exception { String fileNames = StringUtils.EMPTY; Object content = part.getContent(); if (!(content instanceof Multipart)) { if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } if (part.getFileName() != null && !part.getFileName().equals(StringUtils.EMPTY) && part.getInputStream() != null) { String fileName = part.getFileName(); if (fileName.indexOf('?') == -1) { return fileName; } return fileName.substring(fileName.indexOf("=?"), fileName.length() - ((new StringBuilder(fileName)).reverse()).indexOf("=?")); } } else { Multipart mpart = (Multipart) content; for (int i = 0, n = mpart.getCount(); i < n; i++) { if (!StringUtils.EMPTY.equals(fileNames)) { fileNames += ","; } fileNames += getAttachedFileNames(mpart.getBodyPart(i)); } } return fileNames; } }
GetMailMessageService { protected String getAttachedFileNames(Part part) throws Exception { String fileNames = StringUtils.EMPTY; Object content = part.getContent(); if (!(content instanceof Multipart)) { if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } if (part.getFileName() != null && !part.getFileName().equals(StringUtils.EMPTY) && part.getInputStream() != null) { String fileName = part.getFileName(); if (fileName.indexOf('?') == -1) { return fileName; } return fileName.substring(fileName.indexOf("=?"), fileName.length() - ((new StringBuilder(fileName)).reverse()).indexOf("=?")); } } else { Multipart mpart = (Multipart) content; for (int i = 0, n = mpart.getCount(); i < n; i++) { if (!StringUtils.EMPTY.equals(fileNames)) { fileNames += ","; } fileNames += getAttachedFileNames(mpart.getBodyPart(i)); } } return fileNames; }  }
GetMailMessageService { protected String getAttachedFileNames(Part part) throws Exception { String fileNames = StringUtils.EMPTY; Object content = part.getContent(); if (!(content instanceof Multipart)) { if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } if (part.getFileName() != null && !part.getFileName().equals(StringUtils.EMPTY) && part.getInputStream() != null) { String fileName = part.getFileName(); if (fileName.indexOf('?') == -1) { return fileName; } return fileName.substring(fileName.indexOf("=?"), fileName.length() - ((new StringBuilder(fileName)).reverse()).indexOf("=?")); } } else { Multipart mpart = (Multipart) content; for (int i = 0, n = mpart.getCount(); i < n; i++) { if (!StringUtils.EMPTY.equals(fileNames)) { fileNames += ","; } fileNames += getAttachedFileNames(mpart.getBodyPart(i)); } } return fileNames; }  Map<String, String> execute(GetMailMessageInput getMailMessageInput); }
GetMailMessageService { protected String getAttachedFileNames(Part part) throws Exception { String fileNames = StringUtils.EMPTY; Object content = part.getContent(); if (!(content instanceof Multipart)) { if (input.isEncryptedMessage() && part.getContentType() != null && part.getContentType().matches(SecurityConstants.ENCRYPTED_CONTENT_TYPE)) { part = decryptPart((MimeBodyPart) part); } if (part.getFileName() != null && !part.getFileName().equals(StringUtils.EMPTY) && part.getInputStream() != null) { String fileName = part.getFileName(); if (fileName.indexOf('?') == -1) { return fileName; } return fileName.substring(fileName.indexOf("=?"), fileName.length() - ((new StringBuilder(fileName)).reverse()).indexOf("=?")); } } else { Multipart mpart = (Multipart) content; for (int i = 0, n = mpart.getCount(); i < n; i++) { if (!StringUtils.EMPTY.equals(fileNames)) { fileNames += ","; } fileNames += getAttachedFileNames(mpart.getBodyPart(i)); } } return fileNames; }  Map<String, String> execute(GetMailMessageInput getMailMessageInput);  }