Search in sources :

Example 31 with MessagingException

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();
    }
}
Also used : MessagingException(javax.mail.MessagingException) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) InputStream(java.io.InputStream) Literal(com.zimbra.cs.mailclient.imap.Literal)

Example 32 with MessagingException

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);
    }
}
Also used : Message(javax.mail.Message) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) Properties(java.util.Properties) Folder(javax.mail.Folder) NoSuchProviderException(javax.mail.NoSuchProviderException) Session(javax.mail.Session)

Example 33 with MessagingException

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();
    }
}
Also used : Message(javax.mail.Message) InputStreamReader(java.io.InputStreamReader) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) IOException(java.io.IOException) Properties(java.util.Properties) Folder(javax.mail.Folder) BufferedReader(java.io.BufferedReader) NoSuchProviderException(javax.mail.NoSuchProviderException) Session(javax.mail.Session) WebDriverException(org.openqa.selenium.WebDriverException)

Example 34 with MessagingException

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);
    }
}
Also used : MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Example 35 with MessagingException

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);
    }
}
Also used : MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Aggregations

MessagingException (javax.mail.MessagingException)343 MimeMessage (javax.mail.internet.MimeMessage)135 IOException (java.io.IOException)126 InternetAddress (javax.mail.internet.InternetAddress)70 MimeMultipart (javax.mail.internet.MimeMultipart)64 MimeBodyPart (javax.mail.internet.MimeBodyPart)63 Message (javax.mail.Message)49 Properties (java.util.Properties)45 Session (javax.mail.Session)45 InputStream (java.io.InputStream)43 Date (java.util.Date)34 Address (javax.mail.Address)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 ArrayList (java.util.ArrayList)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)26 DataHandler (javax.activation.DataHandler)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)24