commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (EMAIL-133) Problem reading datasource name of inner email-message
Date Thu, 10 Oct 2013 20:19:41 GMT

    [ https://issues.apache.org/jira/browse/EMAIL-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13791946#comment-13791946
] 

Thomas Neidhart commented on EMAIL-133:
---------------------------------------

Another way to retrieve the subject of the inner email would be like this:

{noformat}
        Session session = Session.getDefaultInstance(new Properties());
        MimeMessage message = MimeMessageUtils.createMimeMessage(session, ...);
        MimeMessageParser mimeMessageParser = new MimeMessageParser(message);

        mimeMessageParser.parse();

        List<DataSource> attachmentList = mimeMessageParser.getAttachmentList();

        for (DataSource ds : attachmentList) {
            System.out.println(ds.getName());
            if (ds.getContentType().equals("message/rfc822")) {
                MimeMessage innerMail =
                     MimeMessageUtils.createMimeMessage(session, ds.getInputStream());
                MimeMessageParser parser = new MimeMessageParser(innerMail);
                
                parser.parse();
                
                System.out.println(parser.getSubject());
            }
        }
{noformat}

You can simply parse the inner email with another parser and access all headers / fields of
the message.

> Problem reading datasource name of inner email-message
> ------------------------------------------------------
>
>                 Key: EMAIL-133
>                 URL: https://issues.apache.org/jira/browse/EMAIL-133
>             Project: Commons Email
>          Issue Type: Bug
>    Affects Versions: 1.3.1
>         Environment: Outlook 2007, James 3.0 beta4
>            Reporter: Olaf K.
>         Attachments: Parent EMail.msg
>
>
> Situation:
> - Create EMail in Outlook and attach an other EMail (via Drag&Drop)
>   e.g parent email subject: "Parent EMail", inner email subject: "Inner Email" 
> - after parsing this email I try to acces the attachmentname, but the result is a null-value.
I acpected "Inner Email" as the attachmentname.
> {code}
> mimeMessageParser.parse();
> List<DataSource> attachAsDataSource = mimeMessageParser.getAttachmentList();
> for (DataSource dataSource : attachAsDataSource) {
>   String filename = dataSource.getName();
>   // filename == null
> {code}
> To resolve this behavior I patched the Methode "getDataSourceName" in "MimeMessageParser"
as follows.
> {code}
> ..
> if ("message/rfc822".equalsIgnoreCase(contentType)) {
>   result = ((Message) part.getContent()).getSubject();
>   // START: Optional
>   if (StringUtils.isNotBlank(result)) {
> 	// Add eml-prefix, because binary data is in eml-format and I can use OUTLOOK.EXE /eml
"filename"
> 	result += ".eml";
>   } else {
> 	result = "unknown.eml";
>   }
>   // END: Optional
> }
> ...
> {code}
> Now the inner email is recognized as an email-message and the subject is used for the
name.
> Is there an other way to receive the subject as the attachment-name (without patching)?



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message