Search in sources :

Example 46 with AddressException

use of javax.mail.internet.AddressException in project stanbol by apache.

the class SimpleMailExtractor method extract.

public void extract(URI id, InputStream stream, Charset charset, String mimeType, RDFContainer result) throws ExtractorException {
    try {
        // parse the stream
        MimeMessage message = new MimeMessage(null, stream);
        result.add(RDF.type, NMO.Email);
        // extract the full-text
        StringBuilder buffer = new StringBuilder(10000);
        processMessage(message, buffer, result);
        String text = buffer.toString().trim();
        if (text.length() > 0) {
            result.add(NMO.plainTextMessageContent, text);
            result.add(NIE.plainTextContent, text);
        }
        // extract other metadata
        String title = message.getSubject();
        if (title != null) {
            title = title.trim();
            if (title.length() > 0) {
                result.add(NMO.messageSubject, title);
            }
        }
        try {
            copyAddress(message.getFrom(), NMO.from, result);
        } catch (AddressException e) {
        // ignore
        }
        copyAddress(getRecipients(message, RecipientType.TO), NMO.to, result);
        copyAddress(getRecipients(message, RecipientType.CC), NMO.cc, result);
        copyAddress(getRecipients(message, RecipientType.BCC), NMO.bcc, result);
        MailUtil.getDates(message, result);
    } catch (MessagingException e) {
        throw new ExtractorException(e);
    } catch (IOException e) {
        throw new ExtractorException(e);
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) ExtractorException(org.semanticdesktop.aperture.extractor.ExtractorException) IOException(java.io.IOException)

Aggregations

AddressException (javax.mail.internet.AddressException)46 InternetAddress (javax.mail.internet.InternetAddress)37 MimeMessage (javax.mail.internet.MimeMessage)18 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)17 MessagingException (javax.mail.MessagingException)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)7 Address (javax.mail.Address)7 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 Properties (java.util.Properties)4 Session (javax.mail.Session)4 MimeBodyPart (javax.mail.internet.MimeBodyPart)4 ServiceException (com.zimbra.common.service.ServiceException)3 Account (com.zimbra.cs.account.Account)3 Invite (com.zimbra.cs.mailbox.calendar.Invite)3 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)3 Locale (java.util.Locale)3