List of usage examples for javax.mail Message getSubject
public abstract String getSubject() throws MessagingException;
From source file:org.jahia.modules.gatewaysamples.decoders.MainContentMailDecoder.java
@Override public String decode(Pattern matchingPattern, MailContent parsedMailContent, Message originalMessage) throws Exception { String title = originalMessage.getSubject(); JSONObject jsonObject = new JSONObject(); jsonObject.put("nodetype", "jnt:mainContent"); jsonObject.put("name", StringUtils.defaultIfBlank(title, "Unknown")); jsonObject.put("locale", "en"); jsonObject.put("workspace", Constants.EDIT_WORKSPACE); jsonObject.put("path", "/sites/systemsite/contents"); Map<String, String> properties = new LinkedHashMap<String, String>(); properties.put("body", parsedMailContent.getBody()); properties.put("jcr:title", StringUtils.defaultIfBlank(title, "Unknown")); if (!parsedMailContent.getFiles().isEmpty()) { properties.put("image", parsedMailContent.getFiles().get(0).getFile().getAbsolutePath()); }//www . j ava2 s.c om jsonObject.put("properties", properties); JahiaUser sender = getSender(originalMessage); if (sender != null) { properties.put("username", sender.getName()); } return jsonObject.toString(); }
From source file:org.jahia.modules.gateway.decoders.DefaultMailDecoder.java
public String decode(Pattern matchingPattern, MailContent parsedMailContent, Message originalMessage) throws Exception { String subject = originalMessage.getSubject(); JahiaUser sender = getSender(originalMessage); if (sender == null) { Address[] from = originalMessage.getFrom(); logger.warn(/*from w ww . j a va2 s . com*/ "Unable to find the Jahia user with the e-mail corresponding to the sender of the e-mail message: {}", (from != null && from.length > 0 ? from[0] : null)); return null; } JSONObject jsonObject = new JSONObject(); jsonObject.put("nodetype", "jnt:privateNote"); jsonObject.put("name", subject); jsonObject.put("locale", "en"); jsonObject.put("workspace", Constants.EDIT_WORKSPACE); jsonObject.put("saveFileUnderNewlyCreatedNode", Boolean.TRUE); Map<String, String> properties = new LinkedHashMap<String, String>(); properties.put("note", parsedMailContent.getBody()); properties.put("jcr:title", subject); properties.put("date", DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(System.currentTimeMillis())); jsonObject.put("properties", properties); jsonObject.put("path", getUserManagerService().getUserSplittingRule().getPathForUsername(sender.getName()) + "/contents"); if (!parsedMailContent.getFiles().isEmpty()) { jsonObject.put("files", BaseMailDecoder.toJSON(parsedMailContent.getFiles())); } return jsonObject.toString(); }
From source file:com.cubusmail.gwtui.server.services.ConvertUtil.java
/** * @param folder// w w w .ja v a 2 s.c om * @param msg * @param result * @throws MessagingException */ public static void convertToStringArray(IMailFolder folder, Message msg, String[] result, DateFormat dateFormat, NumberFormat decimalFormat) throws MessagingException { result[MessageListFields.ID.ordinal()] = Long.toString(folder.getUID(msg)); try { result[MessageListFields.ATTACHMENT_FLAG.ordinal()] = Boolean .toString(MessageUtils.hasAttachments(msg)); } catch (IOException e) { // do nothing } result[MessageListFields.READ_FLAG.ordinal()] = Boolean.toString(msg.isSet(Flags.Flag.SEEN)); result[MessageListFields.DELETED_FLAG.ordinal()] = Boolean.toString(msg.isSet(Flags.Flag.DELETED)); result[MessageListFields.ANSWERED_FLAG.ordinal()] = Boolean.toString(msg.isSet(Flags.Flag.ANSWERED)); result[MessageListFields.DRAFT_FLAG.ordinal()] = Boolean.toString(msg.isSet(Flags.Flag.DRAFT)); result[MessageListFields.PRIORITY.ordinal()] = Integer.toString(MessageUtils.getMessagePriority(msg)); if (!StringUtils.isEmpty(msg.getSubject())) { result[MessageListFields.SUBJECT.ordinal()] = msg.getSubject(); } result[MessageListFields.FROM.ordinal()] = MessageUtils.getMailAdressString(msg.getFrom(), AddressStringType.PERSONAL); result[MessageListFields.TO.ordinal()] = MessageUtils .getMailAdressString(msg.getRecipients(RecipientType.TO), AddressStringType.PERSONAL); if (msg.getSentDate() != null) { result[MessageListFields.DATE.ordinal()] = dateFormat.format(msg.getSentDate()); } result[MessageListFields.SIZE.ordinal()] = MessageUtils .formatPartSize(MessageUtils.calculateAttachmentSize(msg.getSize()), decimalFormat); }
From source file:com.mycompany.apsdtask.MessageToEmailConverter.java
EMail convert(Message message) { EMail eMail = new EMail(); try {/*from w ww.java 2 s . c om*/ eMail.setAuthor(((InternetAddress) message.getFrom()[0]).getAddress()); eMail.setDate(message.getSentDate()); eMail.setSubject(message.getSubject()); Object contnet = message.getContent(); eMail.setBody((contnet instanceof MimeMultipart) ? ((MimeMultipart) contnet).getBodyPart(0).getContent().toString() : contnet.toString()); } catch (IOException | MessagingException e) { throw new RuntimeException(e); } return eMail; }
From source file:com.mycompany.apsdtask.domain.MessageToEmailConverter.java
@Override public EMail convert(Message message) { EMail eMail = new EMail(); try {/* w ww . j a v a 2 s . c o m*/ eMail.setAuthor(((InternetAddress) message.getFrom()[0]).getAddress()); eMail.setDate(message.getSentDate()); eMail.setSubject(message.getSubject()); Object contnet = message.getContent(); eMail.setBody((contnet instanceof MimeMultipart) ? ((MimeMultipart) contnet).getBodyPart(0).getContent().toString() : contnet.toString()); } catch (IOException | MessagingException e) { throw new RuntimeException(e); } return eMail; }
From source file:jenkins.plugins.mailer.tasks.MimeMessageBuilderTest.java
@Test public void test_send() throws Exception { MimeMessageBuilder messageBuilder = new MimeMessageBuilder(); messageBuilder.addRecipients("tom.xxxx@jenkins.com").setSubject("Hello").setBody("Testing email"); MimeMessage mimeMessage = messageBuilder.buildMimeMessage(); Mailbox.clearAll();//from w ww. j a v a2 s .c o m Transport.send(mimeMessage); Mailbox mailbox = Mailbox.get("tom.xxxx@jenkins.com"); Assert.assertEquals(1, mailbox.getNewMessageCount()); Message message = mailbox.get(0); Assert.assertEquals("Hello", message.getSubject()); Assert.assertEquals("Testing email", ((MimeMultipart) message.getContent()).getBodyPart(0).getContent().toString()); }
From source file:nl.ordina.bag.etl.mail.handler.MessageHandler.java
public void handle(Message message) throws FileNotFoundException, IOException, MessagingException, JAXBException { if (message.getFrom()[0].toString().matches(fromAddressRegEx) && message.getSubject().matches(subjectRegEx)) { String content = IOUtils.toString(message.getInputStream()); String url = getURL(content); if (url != null) { File mutatiesFile = httpClient.downloadFile(url); mutatiesFileLoader.execute(mutatiesFile); //mutatiesFile.delete(); } else/*from w ww . j av a 2 s . co m*/ logger.warn("Could not retreive url from message '" + message.getSubject() + "' [" + message.getSentDate() + "]"); } else logger.debug("Skipping message '" + message.getSubject() + "' [" + message.getSentDate() + "]"); }
From source file:sendhtml.java
public void collect(BufferedReader in, Message msg) throws MessagingException, IOException { String line;/*from w ww . j a va 2s. co m*/ String subject = msg.getSubject(); StringBuffer sb = new StringBuffer(); sb.append("<HTML>\n"); sb.append("<HEAD>\n"); sb.append("<TITLE>\n"); sb.append(subject + "\n"); sb.append("</TITLE>\n"); sb.append("</HEAD>\n"); sb.append("<BODY>\n"); sb.append("<H1>" + subject + "</H1>" + "\n"); while ((line = in.readLine()) != null) { sb.append(line); sb.append("\n"); } sb.append("</BODY>\n"); sb.append("</HTML>\n"); msg.setDataHandler(new DataHandler(new ByteArrayDataSource(sb.toString(), "text/html"))); }
From source file:com.ikon.util.MailUtils.java
/** * Import messages// ww w . j a v a 2 s . c o m * http://www.jguru.com/faq/view.jsp?EID=26898 * * == Using Unique Identifier (UIDL) == * Mail server assigns an unique identifier for every email in the same account. You can get as UIDL * for every email by MailInfo.UIDL property. To avoid receiving the same email twice, the best way is * storing the UIDL of email retrieved to a text file or database. Next time before you retrieve email, * compare your local uidl list with remote uidl. If this uidl exists in your local uidl list, don't * receive it; otherwise receive it. * * == Different property of UIDL in POP3 and IMAP4 == * UIDL is always unique in IMAP4 and it is always an incremental integer. UIDL in POP3 can be any valid * asc-ii characters, and an UIDL may be reused by POP3 server if email with this UIDL has been deleted * from the server. Hence you are advised to remove the uidl from your local uidl list if that uidl is * no longer exist on the POP3 server. * * == Remarks == * You should create different local uidl list for different email account, because the uidl is only * unique for the same account. */ public static String importMessages(String token, MailAccount ma) throws PathNotFoundException, ItemExistsException, VirusDetectedException, AccessDeniedException, RepositoryException, DatabaseException, UserQuotaExceededException, ExtensionException, AutomationException { log.debug("importMessages({}, {})", new Object[] { token, ma }); Session session = Session.getDefaultInstance(getProperties()); String exceptionMessage = null; try { // Open connection Store store = session.getStore(ma.getMailProtocol()); store.connect(ma.getMailHost(), ma.getMailUser(), ma.getMailPassword()); Folder folder = store.getFolder(ma.getMailFolder()); folder.open(Folder.READ_WRITE); Message messages[] = null; if (folder instanceof IMAPFolder) { // IMAP folder UIDs begins at 1 and are supposed to be sequential. // Each folder has its own UIDs sequence, not is a global one. messages = ((IMAPFolder) folder).getMessagesByUID(ma.getMailLastUid() + 1, UIDFolder.LASTUID); } else { messages = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); } for (int i = 0; i < messages.length; i++) { Message msg = messages[i]; log.info(i + ": " + msg.getFrom()[0] + " " + msg.getSubject() + " " + msg.getContentType()); log.info("Received: " + msg.getReceivedDate()); log.info("Sent: " + msg.getSentDate()); log.debug("{} -> {} - {}", new Object[] { i, msg.getSubject(), msg.getReceivedDate() }); com.ikon.bean.Mail mail = messageToMail(msg); if (ma.getMailFilters().isEmpty()) { log.debug("Import in compatibility mode"); String mailPath = getUserMailPath(ma.getUser()); importMail(token, mailPath, true, folder, msg, ma, mail); } else { for (MailFilter mf : ma.getMailFilters()) { log.debug("MailFilter: {}", mf); if (checkRules(mail, mf.getFilterRules())) { String mailPath = mf.getPath(); importMail(token, mailPath, mf.isGrouping(), folder, msg, ma, mail); } } } // Set message as seen if (ma.isMailMarkSeen()) { msg.setFlag(Flags.Flag.SEEN, true); } else { msg.setFlag(Flags.Flag.SEEN, false); } // Delete read mail if requested if (ma.isMailMarkDeleted()) { msg.setFlag(Flags.Flag.DELETED, true); } // Set lastUid if (folder instanceof IMAPFolder) { long msgUid = ((IMAPFolder) folder).getUID(msg); log.info("Message UID: {}", msgUid); ma.setMailLastUid(msgUid); MailAccountDAO.update(ma); } } // Close connection log.debug("Expunge: {}", ma.isMailMarkDeleted()); folder.close(ma.isMailMarkDeleted()); store.close(); } catch (NoSuchProviderException e) { log.error(e.getMessage(), e); exceptionMessage = e.getMessage(); } catch (MessagingException e) { log.error(e.getMessage(), e); exceptionMessage = e.getMessage(); } catch (IOException e) { log.error(e.getMessage(), e); exceptionMessage = e.getMessage(); } log.debug("importMessages: {}", exceptionMessage); return exceptionMessage; }
From source file:MainClass.java
public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a;// w ww . j a v a 2 s. c om // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) { pr("TO: " + a[j].toString()); InternetAddress ia = (InternetAddress) a[j]; if (ia.isGroup()) { InternetAddress[] aa = ia.getGroup(false); for (int k = 0; k < aa.length; k++) pr(" GROUP: " + aa[k].toString()); } } } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // FLAGS Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } pr("FLAGS: " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) pr("X-Mailer: " + hdrs[0]); else pr("X-Mailer NOT available"); }