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);
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations