Search in sources :

Example 11 with MimeException

use of org.apache.james.mime4j.MimeException in project k-9 by k9mail.

the class Address method parse.

/**
     * Parse a comma separated list of addresses in RFC-822 format and return an
     * array of Address objects.
     *
     * @param addressList
     * @return An array of 0 or more Addresses.
     */
public static Address[] parse(String addressList) {
    if (TextUtils.isEmpty(addressList)) {
        return EMPTY_ADDRESS_ARRAY;
    }
    List<Address> addresses = new ArrayList<Address>();
    try {
        MailboxList parsedList = AddressBuilder.DEFAULT.parseAddressList(addressList).flatten();
        for (int i = 0, count = parsedList.size(); i < count; i++) {
            org.apache.james.mime4j.dom.address.Address address = parsedList.get(i);
            if (address instanceof Mailbox) {
                Mailbox mailbox = (Mailbox) address;
                addresses.add(new Address(mailbox.getLocalPart() + "@" + mailbox.getDomain(), mailbox.getName(), false));
            } else {
                Log.e(LOG_TAG, "Unknown address type from Mime4J: " + address.getClass().toString());
            }
        }
    } catch (MimeException pe) {
        Log.e(LOG_TAG, "MimeException in Address.parse()", pe);
        //but we do an silent failover : we just use the given string as name with empty address
        addresses.add(new Address(null, addressList, false));
    }
    return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}
Also used : Mailbox(org.apache.james.mime4j.dom.address.Mailbox) ArrayList(java.util.ArrayList) MimeException(org.apache.james.mime4j.MimeException) MailboxList(org.apache.james.mime4j.dom.address.MailboxList)

Example 12 with MimeException

use of org.apache.james.mime4j.MimeException in project k-9 by k9mail.

the class MessageHeaderParser method parse.

public static void parse(final Part part, InputStream headerInputStream) throws MessagingException {
    MimeStreamParser parser = getMimeStreamParser();
    parser.setContentHandler(new MessageHeaderParserContentHandler(part));
    try {
        parser.parse(headerInputStream);
    } catch (MimeException me) {
        throw new MessagingException("Error parsing headers", me);
    } catch (IOException e) {
        throw new MessagingException("I/O error parsing headers", e);
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MimeStreamParser(org.apache.james.mime4j.parser.MimeStreamParser) MimeException(org.apache.james.mime4j.MimeException) IOException(java.io.IOException)

Example 13 with MimeException

use of org.apache.james.mime4j.MimeException in project k-9 by k9mail.

the class MimeMessage method parse.

private void parse(InputStream in, boolean recurse) throws IOException, MessagingException {
    mHeader.clear();
    mFrom = null;
    mTo = null;
    mCc = null;
    mBcc = null;
    mReplyTo = null;
    mMessageId = null;
    mReferences = null;
    mInReplyTo = null;
    mSentDate = null;
    mBody = null;
    MimeConfig parserConfig = new MimeConfig();
    // The default is a mere 10k
    parserConfig.setMaxHeaderLen(-1);
    // The default is 1000 characters. Some MUAs generate
    parserConfig.setMaxLineLen(-1);
    // REALLY long References: headers
    // Disable the check for header count.
    parserConfig.setMaxHeaderCount(-1);
    MimeStreamParser parser = new MimeStreamParser(parserConfig);
    parser.setContentHandler(new MimeMessageBuilder());
    if (recurse) {
        parser.setRecurse();
    }
    try {
        parser.parse(new EOLConvertingInputStream(in));
    } catch (MimeException me) {
        throw new MessagingException(me.getMessage(), me);
    }
}
Also used : MimeConfig(org.apache.james.mime4j.stream.MimeConfig) MessagingException(com.fsck.k9.mail.MessagingException) MimeStreamParser(org.apache.james.mime4j.parser.MimeStreamParser) MimeException(org.apache.james.mime4j.MimeException) EOLConvertingInputStream(org.apache.james.mime4j.io.EOLConvertingInputStream)

Example 14 with MimeException

use of org.apache.james.mime4j.MimeException in project tika by apache.

the class MailContentHandler method endBodyPart.

public void endBodyPart() throws MimeException {
    try {
        handler.endElement("p");
        handler.endElement("div");
    } catch (SAXException e) {
        throw new MimeException(e);
    }
}
Also used : MimeException(org.apache.james.mime4j.MimeException) SAXException(org.xml.sax.SAXException)

Aggregations

MimeException (org.apache.james.mime4j.MimeException)14 IOException (java.io.IOException)8 MimeStreamParser (org.apache.james.mime4j.parser.MimeStreamParser)4 SAXException (org.xml.sax.SAXException)4 MessagingException (com.fsck.k9.mail.MessagingException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Entity (org.apache.james.mime4j.dom.Entity)3 Message (org.apache.james.mime4j.dom.Message)3 MessageBuilder (org.apache.james.mime4j.dom.MessageBuilder)3 TextBody (org.apache.james.mime4j.dom.TextBody)3 DefaultMessageBuilder (org.apache.james.mime4j.message.DefaultMessageBuilder)3 MimeConfig (org.apache.james.mime4j.stream.MimeConfig)3 ArrayList (java.util.ArrayList)2 BinaryBody (org.apache.james.mime4j.dom.BinaryBody)2 Body (org.apache.james.mime4j.dom.Body)2 Mailbox (org.apache.james.mime4j.dom.address.Mailbox)2 EOLConvertingInputStream (org.apache.james.mime4j.io.EOLConvertingInputStream)2 EntityState (org.apache.james.mime4j.stream.EntityState)2 TikaInputStream (org.apache.tika.io.TikaInputStream)2 StringBuilder (scala.collection.mutable.StringBuilder)2