List of usage examples for javax.mail MessagingException MessagingException
public MessagingException(String s, Exception e)
From source file:org.nuxeo.ecm.platform.ec.notification.email.EmailHelper.java
/** * Static Method: sendmail(Map mail)./* ww w . j a v a 2 s. c o m*/ * * @param mail A map of the settings */ public void sendmail(Map<String, Object> mail) throws MessagingException { try { sendmail0(mail); } catch (LoginException | IOException | TemplateException | RenderingException e) { throw new MessagingException(e.getMessage(), e); } }
From source file:org.nuxeo.ecm.platform.mail.action.TransformMessageAction.java
public boolean execute(ExecutionContext context) throws MessagingException { Message message = context.getMessage(); if (log.isDebugEnabled()) { log.debug("Transforming message" + message.getSubject()); }/* ww w . j a v a 2 s .c o m*/ if (message.getFrom() != null && message.getFrom().length != 0) { List<String> contributors = new ArrayList<String>(); for (Address ad : message.getFrom()) { contributors.add(safelyDecodeText(ad.toString())); } dcSchema.put("contributors", contributors); dcSchema.put("creator", contributors.get(0)); dcSchema.put("created", message.getReceivedDate()); } if (message.getAllRecipients() != null && message.getAllRecipients().length != 0) { List<String> recipients = new ArrayList<String>(); for (Address address : message.getAllRecipients()) { recipients.add(safelyDecodeText(address.toString())); } mailSchema.put("recipients", recipients); } if (message instanceof MimeMessage) { try { processMimeMessage((MimeMessage) message); } catch (IOException e) { throw new MessagingException(e.getMessage(), e); } } mailSchema.put("text", text.toString()); dcSchema.put("title", message.getSubject()); context.put("transformed", schemas); return true; }
From source file:org.nuxeo.ecm.platform.mail.action.TransformMessageAction.java
/** * "javax.mail.internet.MimeBodyPart" is decoding the file name (with special characters) if it has the * "mail.mime.decodefilename" sysstem property set but the "com.sun.mail.imap.IMAPBodyPart" subclass of MimeBodyPart * is overriding getFileName() and never deal with encoded file names. the filename is decoded with the utility * function: MimeUtility.decodeText(filename); so we force here a filename decode. MimeUtility.decodeText is doing * nothing if the text is not encoded//from w ww.j a v a 2s. c o m */ private static String getFileName(Part mailPart) throws MessagingException { String sysPropertyVal = System.getProperty("mail.mime.decodefilename"); boolean decodeFileName = sysPropertyVal != null && !sysPropertyVal.equalsIgnoreCase("false"); String encodedFilename = mailPart.getFileName(); if (!decodeFileName || encodedFilename == null) { return encodedFilename; } try { return MimeUtility.decodeText(encodedFilename); } catch (UnsupportedEncodingException ex) { throw new MessagingException("Can't decode attachment filename.", ex); } }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.mailer.MailProcessor.java
private static void processRecipients(final MailDefinition definition, final MimeMessage message, final DataFactory dataFactory, final DataRow parameterDataRow) throws ReportDataFactoryException, MessagingException { if (definition.getRecipientsQuery() != null && dataFactory.isQueryExecutable(definition.getRecipientsQuery(), parameterDataRow)) { final TableModel model = wrapWithParameters( dataFactory.queryData(definition.getRecipientsQuery(), parameterDataRow), parameterDataRow); for (int r = 0; r < model.getRowCount(); r++) { String address = null; String name = null;//w ww .j a va 2 s .c o m String type = "TO"; if (model.getColumnCount() >= 3) { type = (String) model.getValueAt(0, 2); } if (model.getColumnCount() >= 2) { name = (String) model.getValueAt(0, 1); } if (model.getColumnCount() >= 1) { address = (String) model.getValueAt(0, 0); } if (address == null) { continue; } if (name == null) { message.addRecipient(parseType(type), new InternetAddress(address, true)); } else { try { message.addRecipient(parseType(type), new InternetAddress(address, name, "UTF-8")); } catch (UnsupportedEncodingException e) { // Should not happen - UTF-8 is safe to use throw new MessagingException("Failed to encode recipient", e); } } } } }
From source file:org.sourceforge.net.javamail4ews.store.EwsFolder.java
@Override public void close(boolean expunge) throws MessagingException { if (mode == javax.mail.Folder.READ_WRITE) { try {//w w w .j a v a 2 s . com if (expunge) { expunge(); } // Update the messages markMessageRead(messages); markMessageRead(unreadMessages); // and the folder itself folder.update(); } catch (Exception e) { // Close anyway throw new MessagingException(e.getMessage(), e); } finally { folder = null; getStore().notifyConnectionListeners(ConnectionEvent.CLOSED); } } }
From source file:org.sourceforge.net.javamail4ews.store.EwsFolder.java
@Override public boolean create(int type) throws MessagingException { try {//ww w . j av a 2 s. co m folder.save(parentFolder.getId()); notifyFolderListeners(FolderEvent.CREATED); return true; } catch (Exception e) { throw new MessagingException(e.getMessage(), e); } }
From source file:org.sourceforge.net.javamail4ews.store.EwsFolder.java
@Override public boolean delete(boolean recurse) throws MessagingException { if (isOpen()) { throw new IllegalStateException("Folder not closed!"); }/* w ww .j a va2 s . co m*/ try { if (recurse) { for (javax.mail.Folder aFolder : list()) { aFolder.delete(recurse); } } else { // Simplest approach if (getMessageCount() > 0) { return false; } } folder.delete(DELETE_MODE); notifyFolderListeners(FolderEvent.DELETED); return true; } catch (Exception e) { throw new MessagingException(e.getMessage(), e); } }
From source file:org.sourceforge.net.javamail4ews.store.EwsFolder.java
@Override public boolean exists() throws MessagingException { if (folder != null) { return true; }// ww w.ja v a2s. c o m try { FolderView view = new FolderView(1); SearchFilter searchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, name); FindFoldersResults lResult = getService().findFolders(WellKnownFolderName.Inbox, searchFilter, view); if (lResult.getTotalCount() > 0) { folder = lResult.getFolders().get(0); INBOX = Folder.bind(getService(), new FolderId(WellKnownFolderName.Inbox)); return true; } else { return false; } } catch (Exception e) { throw new MessagingException(e.getMessage(), e); } }
From source file:org.sourceforge.net.javamail4ews.store.EwsFolder.java
private Message[] deleteMessages(List<EwsMessage> messagesToDelete) throws MessagingException { if (messagesToDelete == null || messagesToDelete.isEmpty()) return new Message[] {}; List<EwsMessage> lDeletedMessages = new ArrayList<EwsMessage>(); for (int i = messagesToDelete.size() - 1; i >= 0; i--) { EwsMessage aMessage = messagesToDelete.get(i); if (aMessage.getFlags().contains(Flag.DELETED)) { try { EmailMessage aRawMessage = aMessage.getEmailMessage(); aRawMessage.delete(DELETE_MODE); } catch (Exception e) { throw new MessagingException(e.getMessage(), e); }/* w w w.j a v a2s. com*/ lDeletedMessages.add(aMessage); messagesToDelete.remove(i); } } Message[] retValue = lDeletedMessages.toArray(new Message[0]); if (retValue.length > 0) { notifyMessageRemovedListeners(true, retValue); } return retValue; }
From source file:org.sourceforge.net.javamail4ews.store.EwsFolder.java
@Override public int getMessageCount() throws MessagingException { if (prefetchItems) { return messages.size(); } else {/*from w ww .j a va 2s . c om*/ try { return folder.getTotalCount(); } catch (Exception e) { throw new MessagingException(e.getMessage(), e); } } }