Search in sources :

Example 11 with MessagingException

use of javax.mail.MessagingException in project rest.li by linkedin.

the class ServerQueryTunnelFilter method onRestRequest.

@Override
public void onRestRequest(RestRequest req, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
    final RestRequest newReq;
    try {
        newReq = QueryTunnelUtil.decode(req, requestContext);
    } catch (MessagingException ex) {
        RestResponse errorResponse = RestStatus.responseForStatus(RestStatus.BAD_REQUEST, ex.toString());
        nextFilter.onResponse(errorResponse, requestContext, wireAttrs);
        return;
    } catch (URISyntaxException ex) {
        RestResponse errorResponse = RestStatus.responseForStatus(RestStatus.BAD_REQUEST, ex.toString());
        nextFilter.onResponse(errorResponse, requestContext, wireAttrs);
        return;
    } catch (Exception ex) {
        nextFilter.onError(ex, requestContext, wireAttrs);
        return;
    }
    nextFilter.onRequest(newReq, requestContext, wireAttrs);
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) MessagingException(javax.mail.MessagingException) RestResponse(com.linkedin.r2.message.rest.RestResponse) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) MessagingException(javax.mail.MessagingException)

Example 12 with MessagingException

use of javax.mail.MessagingException in project rest.li by linkedin.

the class ServerQueryTunnelFilter method onStreamRequest.

@Override
public void onStreamRequest(final StreamRequest req, final RequestContext requestContext, final Map<String, String> wireAttrs, final NextFilter<StreamRequest, StreamResponse> nextFilter) {
    Callback<StreamRequest> callback = new Callback<StreamRequest>() {

        @Override
        public void onError(Throwable e) {
            if (e instanceof MessagingException || e instanceof URISyntaxException) {
                RestResponse errorResponse = RestStatus.responseForStatus(RestStatus.BAD_REQUEST, e.toString());
                nextFilter.onResponse(Messages.toStreamResponse(errorResponse), requestContext, wireAttrs);
            } else {
                nextFilter.onError(e, requestContext, wireAttrs);
            }
        }

        @Override
        public void onSuccess(StreamRequest newReq) {
            nextFilter.onRequest(newReq, requestContext, wireAttrs);
        }
    };
    // the entire request would be buffered in memory if decoding is needed
    // this usually is not a problem as request with extremely query parameters is usually get request with no body
    QueryTunnelUtil.decode(req, requestContext, callback);
}
Also used : Callback(com.linkedin.common.callback.Callback) MessagingException(javax.mail.MessagingException) RestResponse(com.linkedin.r2.message.rest.RestResponse) URISyntaxException(java.net.URISyntaxException) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Example 13 with MessagingException

use of javax.mail.MessagingException in project hudson-2.x by hudson.

the class MailSender method execute.

public boolean execute(AbstractBuild<?, ?> build, BuildListener listener) throws InterruptedException {
    try {
        MimeMessage mail = getMail(build, listener);
        if (mail != null) {
            // if the previous e-mail was sent for a success, this new e-mail
            // is not a follow up
            AbstractBuild<?, ?> pb = build.getPreviousBuild();
            if (pb != null && pb.getResult() == Result.SUCCESS) {
                mail.removeHeader("In-Reply-To");
                mail.removeHeader("References");
            }
            Address[] allRecipients = mail.getAllRecipients();
            if (allRecipients != null) {
                StringBuilder buf = new StringBuilder("Sending e-mails to:");
                for (Address a : allRecipients) buf.append(' ').append(a);
                listener.getLogger().println(buf);
                Mailer.descriptor().send((HudsonMimeMessage) mail);
                build.addAction(new MailMessageIdAction(mail.getMessageID()));
            } else {
                listener.getLogger().println(Messages.MailSender_ListEmpty());
            }
        }
    } catch (MessagingException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } finally {
        CHECKPOINT.report();
    }
    return true;
}
Also used : Address(javax.mail.Address) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException)

Example 14 with MessagingException

use of javax.mail.MessagingException in project jodd by oblac.

the class ReceiveMailSession method receive.

/**
	 * Receives all emails that matches given {@link EmailFilter filter}
	 * and set given flags. Both filter and flags to set are optional.
	 * If flags to set is not provided, it forces 'seen' flag to be unset.
	 */
public ReceivedEmail[] receive(EmailFilter filter, Flags flagsToSet) {
    if (folder == null) {
        useDefaultFolder();
    }
    Message[] messages;
    try {
        if (filter == null) {
            messages = folder.getMessages();
        } else {
            messages = folder.search(filter.getSearchTerm());
        }
        if (messages.length == 0) {
            return null;
        }
        // process messages
        ReceivedEmail[] emails = new ReceivedEmail[messages.length];
        for (int i = 0; i < messages.length; i++) {
            Message msg = messages[i];
            // we need to parse message BEFORE flags are set!
            emails[i] = new ReceivedEmail(msg);
            if (flagsToSet != null) {
                emails[i].setFlags(flagsToSet);
                msg.setFlags(flagsToSet, true);
            }
            if (flagsToSet == null && !emails[i].isSeen()) {
                msg.setFlag(Flags.Flag.SEEN, false);
            }
        }
        return emails;
    } catch (MessagingException msex) {
        throw new MailException("Failed to fetch messages", msex);
    }
}
Also used : Message(javax.mail.Message) MessagingException(javax.mail.MessagingException)

Example 15 with MessagingException

use of javax.mail.MessagingException in project jodd by oblac.

the class ReceiveMailSession method getAllFolders.

// ---------------------------------------------------------------- folders
/**
	 * Returns list of all folders. You can use these names in
	 * {@link #useFolder(String)} method.
	 */
public String[] getAllFolders() {
    Folder[] folders;
    try {
        folders = store.getDefaultFolder().list("*");
    } catch (MessagingException msex) {
        throw new MailException("Failed to connect to folder", msex);
    }
    String[] folderNames = new String[folders.length];
    for (int i = 0; i < folders.length; i++) {
        Folder folder = folders[i];
        folderNames[i] = folder.getFullName();
    }
    return folderNames;
}
Also used : MessagingException(javax.mail.MessagingException) Folder(javax.mail.Folder)

Aggregations

MessagingException (javax.mail.MessagingException)324 MimeMessage (javax.mail.internet.MimeMessage)126 IOException (java.io.IOException)125 InternetAddress (javax.mail.internet.InternetAddress)64 MimeMultipart (javax.mail.internet.MimeMultipart)60 MimeBodyPart (javax.mail.internet.MimeBodyPart)58 Message (javax.mail.Message)45 Session (javax.mail.Session)43 InputStream (java.io.InputStream)41 Properties (java.util.Properties)38 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 Address (javax.mail.Address)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 ServiceException (com.zimbra.common.service.ServiceException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)25 DataHandler (javax.activation.DataHandler)23 BodyPart (javax.mail.BodyPart)23