[prev in list] [next in list] [prev in thread] [next in thread] 

List:       geronimo-user
Subject:    geronimo-javamail_1.4_spec 1.7.1 bug
From:       "Edward W. Rouse" <erouse () comsquared ! com>
Date:       2012-08-16 17:18:10
Message-ID: 022601cd7bd3$1c10c770$54325650$ () com
[Download RAW message or body]

In my webapp I have a program that processes email attachments. This works
fine using the standard mail.jar file (javax.mail). Since it also consumes
web services, I recently upgraded to using cxf, which has a dependency on
geronimo-javamail_1.4_spec. With the geronimo-javamail_1.4_spec jar file in
place, the attachment processing breaks. I have only tested with Outlook
since that is what most customers are using to send the emails with
attachments and I know those are no longer working once the
geronimo-javamail_1.4_spec jar file is in place.

Code below is basically the process. Instead of getting the multipart as I
do using mail, I get no attachment at all. It looks like I get a simple
String with all of the info contained in it. The content type is always
text/plain and there are no headers returned from msg.getAllHeaders().

Is this a known issue? Is there a workaround?

I use it as follows:

Store store;
store.connect(host, username, password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message[] msgs = folder.getMessages();
for(int i = 0, counter = 0; i < msgs.length && i < messageLimit; i++)
{
  Message msg = msgs[i]; 
  ArrayList<Part> attachments = getAttachments(msg);
}


  public ArrayList<Part> getAttachments(Part msg) throws MessagingException,
IOException
  {
    ArrayList<Part> attachments = new ArrayList<Part>();
    log.info("Message ContentType is '" + msg.getContentType() + "'");
    if(msg.getContentType().toLowerCase().startsWith("multipart/"))
    {
      Multipart body = (Multipart)msg.getContent();

      attachments = new ArrayList<Part>();
      for(int j = 0; j < body.getCount(); j++)
      {
        Part part = body.getBodyPart(j);
        String disposition = part.getDisposition();
        if(part.getContentType().toLowerCase().startsWith("message/"))
        {
          log.info("Searching for nested attachments in attached message,
content type: " + part.getContentType());
          List<Part> list = getAttachments((Part)part.getContent());
          if(list != null)
          {
            if(attachments == null)
              attachments = new ArrayList<Part>();
            attachments.addAll(list);
          }
        }
        else if(disposition == null)
        {
          if(part.getFileName() == null)
          {
            log.debug("No content disposition, no file name, content type: "
+ part.getContentType());
          }
          else
          {
            log.info("No content disposition, file name: " +
part.getFileName());
            attachments.add(part);
          }
        }
        else if(disposition.toLowerCase().equals(Message.ATTACHMENT))
        {
          log.debug("Found content disposition, file name: " +
part.getFileName());
          attachments.add(part);
        }
        else if(part.getFileName() != null)
        {
          log.info("Content disposition is \"" + part.getDisposition() +
"\", file name: " + part.getFileName());
          attachments.add(part);
        }
      }
    }
    else if(msg.getFileName() != null)
    {
      ContentType mimeType = new ContentType(msg.getContentType());
      log.info("Message is not in multipart MIME format, but does have a
file name "
          + "so the whole message body will be treated as an attachment. The
content type is \"" + mimeType.getBaseType()
          + "\", and the file name is \"" + msg.getFileName() + "\"");
      attachments.add((Part)msg);
    }
    else
    {
      ContentType mimeType = new ContentType(msg.getContentType());
      log.info("Message content type is " + mimeType.getBaseType());

      // Try to uudecode the body if it is a text type
      if(mimeType.getBaseType().startsWith("text/"))
      {
        log.info("Looking for uuencoded data in body text");
        attachments = uudecode((String)msg.getContent());
      }
    }

    return attachments;
  }


Edward W. Rouse


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic