use of javax.mail.MessagingException in project zm-mailbox by Zimbra.
the class ImapAppender method append.
private long append(MessageInfo mi) throws IOException, ServiceException {
InputStream is = mi.data.getInputStream();
Literal lit = new Literal(is, mi.data.getSize());
try {
return hasAppendUid ? append(mi, lit) : appendSlow(mi, lit);
} catch (MessagingException e) {
throw ServiceException.FAILURE("Parsing error", e);
} finally {
is.close();
}
}
use of javax.mail.MessagingException in project selenium-tests by Wikia.
the class EmailUtils method deleteAllEmails.
public static void deleteAllEmails(String userName, String password) {
try {
// establishing connections
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
Store store = session.getStore("imaps");
store.connect("imap.googlemail.com", userName, password);
// getInbox
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
if (messages.length != 0) {
for (int i = 0; i < messages.length; i++) {
messages[i].setFlag(Flags.Flag.DELETED, true);
}
} else {
PageObjectLogging.log("Mail", "There are no messages in inbox", true);
}
store.close();
} catch (NoSuchProviderException e) {
PageObjectLogging.log("Mail", e, false);
} catch (MessagingException e) {
PageObjectLogging.log("Mail", e, false);
}
}
use of javax.mail.MessagingException in project selenium-tests by Wikia.
the class EmailUtils method getFirstEmailContent.
public static String getFirstEmailContent(String userName, String password, String subject) {
try {
PageObjectLogging.logInfo("Checking emails for " + userName + " that contain '" + subject + "'");
// establishing connections
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.googlemail.com", userName, password);
// getInbox
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message[] messages = null;
boolean forgottenPasswordMessageFound = false;
Message magicMessage = null;
for (int i = 0; !forgottenPasswordMessageFound; i++) {
messages = inbox.getMessages();
PageObjectLogging.log("Mail", "Waiting for the message", true);
Thread.sleep(2000);
for (Message message : messages) {
if (message.getSubject().contains(subject)) {
forgottenPasswordMessageFound = true;
magicMessage = message;
}
}
if (i > 15) {
throw new WebDriverException("Mail timeout exceeded");
}
}
PageObjectLogging.log("Mail", "Mail arrived", true);
Message m = magicMessage;
String line;
StringBuilder builder = new StringBuilder();
InputStreamReader in = new InputStreamReader(m.getInputStream());
BufferedReader reader = new BufferedReader(in);
while ((line = reader.readLine()) != null) {
builder.append(line);
}
store.close();
return builder.toString();
} catch (NoSuchProviderException e) {
PageObjectLogging.log("getFirstEmailContent", e, false);
throw new WebDriverException();
} catch (MessagingException | IOException | InterruptedException e) {
PageObjectLogging.log("getFirstEmailContent", e, false);
throw new WebDriverException();
}
}
use of javax.mail.MessagingException in project zm-mailbox by Zimbra.
the class JavaMailMimeMultipart method setPreamble.
@Override
public synchronized void setPreamble(String preamble) throws MessagingException {
if (ZPARSER) {
com.zimbra.common.mime.MimeBodyPart part = null;
if (preamble != null) {
part = new com.zimbra.common.mime.MimeBodyPart(null);
try {
part.setText(preamble);
} catch (IOException ioe) {
throw new MessagingException("error converting preamble to byte[]", ioe);
}
}
zmultipart.setPreamble(part);
} else {
super.setPreamble(preamble);
}
}
use of javax.mail.MessagingException in project zm-mailbox by Zimbra.
the class JavaMailMimeBodyPart method setContent.
@Override
public void setContent(Object o, String type) throws MessagingException {
if (ZPARSER) {
com.zimbra.common.mime.ContentType ctype = new com.zimbra.common.mime.ContentType(type);
if (o instanceof JavaMailMimeMultipart) {
setContent((Multipart) o);
setHeader("Content-Type", type);
} else if (o instanceof JavaMailMimeMessage) {
replaceInParent(((JavaMailMimeMessage) o).getZimbraMimeMessage());
setHeader("Content-Type", type);
this.jmcontent = o;
} else if (o instanceof String) {
if (ctype.getPrimaryType().equals("text")) {
setText((String) o, ctype.getParameter("charset"), ctype.getSubType());
setHeader("Content-Type", type);
} else {
try {
setDataSource(new ByteArrayDataSource((String) o, type));
} catch (IOException ioe) {
throw new MessagingException("error setting string content", ioe);
}
}
} else {
setDataHandler(new DataHandler(o, type));
}
} else {
super.setContent(o, type);
}
}
Aggregations