@Test public void invalidAddressesShouldBeAllowed() throws Exception { String headers = "From: user <userdomain>\n" + "To: user1 <user1domain>, user2 <user2domain>\n" + "Cc: usercc <userccdomain>\n" + "Bcc: userbcc <userbccdomain>\n" + "Subject: test subject\n"; MetaDataWithContent testMail = MetaDataWithContent.builder() .uid(MessageUid.of(2)) .flags(new Flags(Flag.SEEN)) .size(headers.length()) .internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8))) .attachments(ImmutableList.of()) .mailboxId(MAILBOX_ID) .messageId(MessageId.of("user|box|2")) .build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); Emailer user = Emailer.builder().name("user").email("userdomain").allowInvalid().build(); Emailer user1 = Emailer.builder().name("user1").email("user1domain").allowInvalid().build(); Emailer user2 = Emailer.builder().name("user2").email("user2domain").allowInvalid().build(); Emailer usercc = Emailer.builder().name("usercc").email("userccdomain").allowInvalid().build(); Emailer userbcc = Emailer.builder().name("userbcc").email("userbccdomain").allowInvalid().build(); assertThat(testee.getFrom()).contains(user); assertThat(testee.getTo()).contains(user1, user2); assertThat(testee.getCc()).contains(usercc); assertThat(testee.getBcc()).contains(userbcc); }
private static void updateFromUtorrent( String logFilePath, String label, String title, String secret) { XBMCUpdate updateServer = new XBMCUpdate("xbmc", "xbmc", "10.0.0.5", "8081"); updateServer.sendUpdateRequest(); DownloadLog log = new DownloadLog(label, title); String toEmail = null; String password = null; ReadUserXML reader; try { reader = new ReadUserXML(USER_XML_PATH); reader.parseXML(); EncryptText encrypter = new EncryptText(secret); toEmail = encrypter.decryptString(reader.getUsername()); password = encrypter.decryptString(reader.getPassword()); } catch (FileNotFoundException | XMLStreamException e) { logger.error(e); } Emailer emailer = new Emailer(); emailer.setCredentials(toEmail, password); String fromEmail = "*****@*****.**"; emailer.setToAddress(toEmail); emailer.setFromAddress(fromEmail); emailer.setMessageSubject("New Torrent Downloaded"); emailer.setMessageBody(log.toString()); emailer.sendEmail("true", "smtp.gmail.com", "587", false); File logFile = new File(logFilePath); if (logFile.exists()) { try (FileWriter writer = new FileWriter(logFile, true)) { writer.write(log.toString()); writer.write("\n"); System.out.println("Added to log: \n\t" + log.toString()); } catch (IOException e) { logger.info("logFilePath invalid"); logger.error("Could not find log file", e); } } else { System.out.printf("Directory %s does not exist%n", logFile.getAbsolutePath()); } }
protected void setUp() throws Exception { super.setUp(); // Configure log4j Properties props = new Properties(); props.setProperty("log4j.rootLogger", "debug, cons"); props.setProperty("log4j.appender.cons", "org.apache.log4j.ConsoleAppender"); props.setProperty( "log4j.appender.cons.layout", "org.sipfoundry.commons.log4j.SipFoundryLayout"); props.setProperty("log4j.appender.cons.layout.facility", "sipXivr"); PropertyConfigurator.configure(props); m_testDir = new File("/tmp/MessagesTest/"); if (m_testDir.isDirectory()) { FileUtils.forceDelete(m_testDir); } m_testDir.mkdir(); m_mailstoreDir = new File(m_testDir, "mailstore"); m_mailstoreDir.mkdir(); m_userDir = new File(m_mailstoreDir, "user"); m_userDir.mkdir(); m_inboxDir = new File(m_userDir, "inbox"); m_inboxDir.mkdir(); m_savedDir = new File(m_userDir, "saved"); m_savedDir.mkdir(); m_deletedDir = new File(m_userDir, "deleted"); m_deletedDir.mkdir(); // Tell MWI & email not to bother contacting an external server Mwi.setJustTesting(true); Emailer.setJustTesting(true); m_mw = new MessageDescriptorWriter(); m_md = new MessageDescriptor(); m_md.setId("woof"); m_md.setFromUri("user@dog"); m_md.setDurationSecs(42); m_md.setTimestamp(System.currentTimeMillis()); m_md.setSubject("Voice Message"); m_md.setPriority(Priority.NORMAL); }
public static void main(String[] args) { if (args.length < 1) { System.out.println("Please give the configuration file name as first argument"); return; } Map<String, Long> executionTimes = new HashMap<String, Long>(); InputSource inputSource = new InputSource(args[0]); List<Test> tests = getTests(inputSource); if (tests == null) return; Emailer emailer = parseEmailer(inputSource); if (emailer == null) return; List<List<String>> outputs = new ArrayList<List<String>>(); for (Test test : tests) { try { System.out.println("Running test " + test.getName()); long startTime = System.currentTimeMillis(); BufferedReader bufferedReader = null; for (int i = 0; i < test.getNRuns(); i++) { Process process = Runtime.getRuntime().exec(test.getCommand()); if (test.getOutput().equals("console")) { bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); } else { bufferedReader = new BufferedReader(new FileReader(test.getOutput())); } process.waitFor(); } executionTimes.put(test.getName(), System.currentTimeMillis() - startTime); outputs.add(getLines(bufferedReader)); System.out.println("Test " + test.getName() + " executed"); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } String message = ""; int size = tests.size(); for (int i = 0; i < size; i++) { for (int j = 0; j < i; j++) { String differences = Diff.diff(outputs.get(i), outputs.get(j)); if (!differences.isEmpty()) { message += "Differences between " + tests.get(j).getName() + " and " + tests.get(i).getName() + " tests\n"; message += differences; } } } System.out.println("Sending e-mails"); if (!message.isEmpty()) { message = "Some tests failed:\n" + message; } else { message = "Tests run successfully\n"; } message += "Time of execution:\n"; for (String name : executionTimes.keySet()) { message += name + " : " + executionTimes.get(name) + "ms\n"; } emailer.send(message); System.out.println("E-mails sent"); }
@Test public void headersShouldBeSetIntoMessage() throws Exception { String headers = "From: user <user@domain>\n" + "Subject: test subject\n" + "To: user1 <user1@domain>, user2 <user2@domain>\n" + "Cc: usercc <usercc@domain>\n" + "Bcc: userbcc <userbcc@domain>\n" + "Reply-To: \"user to reply to\" <user.reply.to@domain>\n" + "In-Reply-To: <*****@*****.**>\n" + "Other-header: other header value"; MetaDataWithContent testMail = MetaDataWithContent.builder() .uid(MessageUid.of(2)) .flags(new Flags(Flag.SEEN)) .size(headers.length()) .internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8))) .attachments(ImmutableList.of()) .mailboxId(MAILBOX_ID) .messageId(MessageId.of("user|box|2")) .build(); Emailer user = Emailer.builder().name("user").email("user@domain").build(); Emailer user1 = Emailer.builder().name("user1").email("user1@domain").build(); Emailer user2 = Emailer.builder().name("user2").email("user2@domain").build(); Emailer usercc = Emailer.builder().name("usercc").email("usercc@domain").build(); Emailer userbcc = Emailer.builder().name("userbcc").email("userbcc@domain").build(); Emailer userRT = Emailer.builder().name("user to reply to").email("user.reply.to@domain").build(); ImmutableMap<String, String> headersMap = ImmutableMap.<String, String>builder() .put("Cc", "usercc <usercc@domain>") .put("Bcc", "userbcc <userbcc@domain>") .put("Subject", "test subject") .put("From", "user <user@domain>") .put("To", "user1 <user1@domain>, user2 <user2@domain>") .put("Reply-To", "\"user to reply to\" <user.reply.to@domain>") .put("In-Reply-To", "<*****@*****.**>") .put("Other-header", "other header value") .put("Date", "Tue, 14 Jul 2015 12:30:42 +0000") .put("MIME-Version", "1.0") .build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); Message expected = Message.builder() .id(MessageId.of("user|box|2")) .blobId(BlobId.of("2")) .threadId("user|box|2") .mailboxIds(ImmutableList.of(MAILBOX_ID)) .inReplyToMessageId("<*****@*****.**>") .headers(headersMap) .from(user) .to(ImmutableList.of(user1, user2)) .cc(ImmutableList.of(usercc)) .bcc(ImmutableList.of(userbcc)) .replyTo(ImmutableList.of(userRT)) .subject("test subject") .date(ZONED_DATE) .size(headers.length()) .preview("(Empty)") .textBody("") .build(); assertThat(testee).isEqualToComparingFieldByField(expected); }