To header with Invalid address was dropped

Hi there,

This is refer to another thread. How to create MapiAttachment? How to bypass address validation?

When we convert message from EML to MSG format, we want to keep all data even the data was malformed. Especially the email address.

For example: the header below was malformed:

To: aabc, email1, email@email2.com, xaasdfas, xllalsdf, aa@aa@cc, a"xasadf@xam.com

If I used the code below to convert it to MSG, the whole TO header was dropped.

Sample code:
{code}
private void convertEmlToMsg(File emlFile) throws Exception {
File outputFile = new File(outDir, emlFile.getName());
try(InputStream is = new FileInputStream(emlFile);
InputStream bis = new BufferedInputStream (is);
OutputStream os = new FileOutputStream(outputFile);
OutputStream bos = new BufferedOutputStream(os)) {

MailMessage mailMsg = MailMessage.load(bis, MessageFormat.getEml());
mailMsg.save(bos, MessageFormat.getEml());

MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg, MapiConversionOptions.getUnicodeFormat());

// The MapiMessage outlookMsg is missing to header
}

}
{code}

Also, if we tried to add headers manually:

{code}
MailMessage mailMsg = new MailMessage();

addToAddr(mailMsg, “1, 2, 3, aa@aa.com, xyz, aa”);
addToAddr(mailMsg, “2.”);
addToAddr(mailMsg, “3.abc@”);
addToAddr(mailMsg, “4.abc@abc”);
addToAddr(mailMsg, “5.abc@a.a”);
addToAddr(mailMsg, “6.abc@a@a”);
addToAddr(mailMsg, “7.abc@"aaa”);
private void addToAddr(MailMessage mailMsg, String addr) {
try {
mailMsg.getHeaders().add_(“to”, addr);
} catch(Exception ex) {
System.out.println("Invalid: " + addr);
}
}
{code}

We got output:
Invalid: 2.
Invalid: 3.abc@
Invalid: 6.abc@a@a
Invalid: 7.abc@"aaa

The final to header we got in the MSG file is: To: 1; 2; 3; aa@aa.com; xyz; aa


We know they are invalid. But we want to keep these invalid addresses.
When we convert EML to MSG file, we don’t want to drop any data.

Thanks,

Ying

Hi Ying,


Thank you for writing to Aspose support team.

I was able to observe the differences in output as compared to MS Outlook for the conversion of this EML to MSG and have logged it as NETWRKJAVA-33430 in our issue tracking system for further investigation by our development team. We’ll notify you here once there is some information available in this regard.

Thanks!

Do you have an EST on how long it will take to fix this issue?

Best regards,

Ying

Hi Ying,


The issue is planned to be fixed in Aspose.Email for Java 4.9.0 that is due in the first week of January 2015. We’ll notify you here once there is some further information available in this regard.

Hi Kashif,

When are you going to release the new version. Is the fix included in the new version? Just checked and the downloadable version is still 4.8.0.

Thanks,

Ying

Hi Ying,


The issue is planned to be fixed in Aspose.Email for Java 4.9.0 which is due for release at the end of next week. The release was delayed due to some further QA and we’ll notify you here once the fix version is available for download. We are sorry for the inconvenience caused to you.

Hi Kashif,

I just tried the new version and it processed the address better but not perfect.
It processed the message differently on EML file and MSG file.

  1. From eml file:
    Wrong behavior.
    MailMessage mailMsg = MailMessage.load(bis, MessageFormat.getMsg());
    MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg, MapiConversionOptions.getUnicodeFormat());
    The invalid char in the address was dropped.
    For example: [a"xasadf@xam.com](mailto:a%22xasadf@xam.com) was changed to: [axasadf@xam.com](mailto:axasadf@xam.com)

  2. From msg file:
    Expected result, the invalid address was kept.
    [a"xasadf@xam.com](mailto:a%22xasadf@xam.com) is shown as [a"xasadf@xam.com](mailto:a%22xasadf@xam.com) in outlook.

  3. Could not add the invalid address to the header manually
    mailMsg.getHeaders().add_(“to”, "7.abc@“aaa”);

class com.aspose.email.system.exceptions.FormatException: An invalid character was found in the mail header.
com.aspose.email.qj.d(Unknown Source)
com.aspose.email.qj.e(Unknown Source)
com.aspose.email.qj.a(Unknown Source)
com.aspose.email.qj.b(Unknown Source)
com.aspose.email.MailAddressCollection.b(Unknown Source)
com.aspose.email.MailAddressCollection.a(Unknown Source)
com.aspose.email.jl.a(Unknown Source)
com.aspose.email.HeaderCollection.add_(Unknown Source)

Also, random exception when we use two set of threads.

1. A set of threads to read messages files from DISK, then convert them to MapiMessage object
2. One thread to add MapiMessage objects to PersonalStorage
List msgs = …
folder.addMessages(msgs);

This code worked fine if for #1, if message files were EML files.
But it throw random exceptions if the message files were in outlook MSG format.

Sample code:
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadNumber);
for(int i=0; i<threadNumber; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
processMessages();
} catch (Exception e) {
e.printStackTrace();
} finally {
convertDone.incrementAndGet();
}
}
});
}
//main thread
PersonalStorage pst = PersonalStorage.create(pstFile.getAbsolutePath(), FileFormatVersion.Unicode);
FolderInfo folder = pst.getRootFolder().addSubFolder(“mail”);
while(…) {
List msgs = pollMessages(); //poll MapiMessage created in threads
folder.addMessages(msgs);
}

private void processMessages() {
while(true) {
read files from disk
MailMessage mailMsg = MailMessage.load(bis, MessageFormat.getMsg());
MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg, MapiConversionOptions.getUnicodeFormat());
add outlookMsg to a queue for main thread to poll
}
}

Hi Ying,

We are sorry for a delayed response as we are still investigating the issue at our end. I’ll request you to please spare us some time in this regard. We’ll soon share our findings here with you in this regard.

Hi Kashif,

Any update?
There are a couple of issues we have with the latest release
1. It still reject malformed addresses when we use mailMsg.getHeaders().add("7.abc@“aaa”)
We want to keep any malformed address because we just want to use it as a tool create PST file.
2. Reject invalid content-type
It will throw exception like: “The specified content type is invalid.”
Again, we want to keep malformed content-type.
3. Reject on wrong attachment structure
exception like "Multipart mime document has incorrect structure"

In short, we plan to use Aspose.email to create PST file. So we would like to keep the messages’ original format, no matter it’s malformed or not. But Aspose.email has too many validation code, and rejected some malformed messages. I didn’t know why Aspose.email has to validate them. Is it possible to add a switch to turn off those validation code?

Thanks,

Ying

Hi Ying,

I have gone through all the issues and following are the comments:

billowgy:
It processed the message differently on EML file and MSG file.

1. From eml file:
Wrong behavior.
MailMessage mailMsg = MailMessage.load(bis, MessageFormat.getMsg());
MapiMessage outlookMsg = MapiMessage.fromMailMessage(mailMsg, MapiConversionOptions.getUnicodeFormat());
The invalid char in the address was dropped.
For example: a"xasadf@xam.com was changed to: axasadf@xam.com

2. From msg file:
Expected result, the invalid address was kept.
a"xasadf@xam.com is shown as a"xasadf@xam.com in outlook.

Comments:

I tried with both EML and MSG file as source having double quote in address and saved them on disc but could not re-produce the issue as same address was displayed in Outlook. However if I create MailMessage using Aspose.Email having double quote in address and save it as MapiMessage on disc, the issue is re-produced and double quote is removed from the address.

billowgy:
3. Could not add the invalid address to the header manually
mailMsg.getHeaders().add_("to", "7.abc@\"aaa");

Comments:

This issue is reproduced here.

billowgy:
Also, random exception when we use two set of threads.

1. A set of threads to read messages files from DISK, then convert them to MapiMessage object
.....
.....
.....

Comments:

Regarding the code here, I am afraid that I could not compile it due to missing definition of convertDone.incrementAndGet() and pollMessages(). Could you please send the complete code which can be used here to reproduce the scenario here?

billowgy:
Any update?
There are a couple of issues we have with the latest release
1. It still reject malformed addresses when we use mailMsg.getHeaders().add("7.abc@\"aaa")
We want to keep any malformed address because we just want to use it as a tool create PST file.

Comments:

This issue is re-produced here.

billowgy:
2. Reject invalid content-type
It will throw exception like: "The specified content type is invalid."
Again, we want to keep malformed content-type.
3. Reject on wrong attachment structure
exception like "Multipart mime document has incorrect structure"

Comments:

Could you please provide sample files to re-produce this scenario here as I could not re-produce it here with available sample files?

billowgy:
In short, we plan to use Aspose.email to create PST file. So we would like to keep the messages' original format, no matter it's malformed or not. But Aspose.email has too many validation code, and rejected some malformed messages. I didn't know why Aspose.email has to validate them. Is it possible to add a switch to turn off those validation code?

Comments:

I have passed on this information to developer to provide their comments regarding the removal of double quote from address and exception while saving address through Headers. You will be notified as soon as some feedback is received in this regard. Please be patient while we discuss this matter here with the development team.

We are sorry for any inconvenience caused to you.


Hi kashif,

Please check attached file.
When I was testing, I have 200+ samples in the srcdir.
And it will throw random failure on different files, for example

There was three messages which always fail, and I attached them in the zip file.

Run it with parameter:-d /tmp/pst/srcdir -o /tmp/pst/outdir -p /tmp/pst/output1.pst -t 8
here -d is the source dir for your .msg, .eml files.

I just found that for .eml file, we had exactly the same random failure issue with multiple threads. So the problem should be a general issue. Not sure whether its my code bug, or inside your library.

Thanks,

Ying

{code}
Failed:C:\tmp\pst\srcdir\attachment-wrongname.eml:The specified content type is invalid.
Failed:C:\tmp\pst\srcdir\eml-with-nested-eml-reusing-boundary.eml:Multipart mime document has incorrect structure
Failed:C:\tmp\pst\srcdir\encoded-nonascii-filename.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-2010-distribution-lists.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-2010-normal-on-behalf-of.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-2010-multiple-auto-forwards.eml:null
Failed:C:\tmp\pst\srcdir\eml-with-nested-eml-attachments.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-bcc.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-nested-wnestedmsg-unwrapped.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-three.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-text-message-in-different-parts.eml:null
Failed:C:\tmp\pst\srcdir\envjournal-with-attachments.eml:null
Failed:C:\tmp\pst\srcdir\gr_fieldset_ib.eml:null
Failed:C:\tmp\pst\srcdir\links_in_html.eml:null
Failed:C:\tmp\pst\srcdir\png renamed as pdf.eml:null
Failed:C:\tmp\pst\srcdir\unbalanced-quotes-in-content-type.eml:The specified content type is invalid.
{code}


BTW, my pom.xml has
{code}

commons-lang
commons-lang
2.5


commons-io
commons-io
2.0.1


javax.mail
mail
1.4.2.gr10

{code}

Hi Ying,


Thank you for providing more sample files which I have provided to developers for their analysis. Please be patient as I will write back here as soon as I get feedback from the developers.

Hi Kashif,

Any update?

Thanks,

Ying

Hi Ying,

Aspose.Email provides option to load email without the validation as shown in the following code:

MailMessageLoadOptions option = new MailMessageLoadOptions();
option.setFileCompatibilityMode(FileCompatibilityMode.SkipValidityChecking);
option.setMessageFormat(MessageFormat.getEml());
MailMessage msg = MailMessage.load("attachment-wrongname.eml", option);
// Creating msg object for outlook
MapiConversionOptions option2 = new MapiConversionOptions();
option2.setFormat(OutlookMessageFormat.Unicode);
MapiMessage mapi = MapiMessage.fromMailMessage(msg, option2);
Above code does not raise exception for issues in source EML files. However currently there is no option to save the mails having invalid characters in email address to MapiMessage. This requirement is logged as enhancement in our issue tracking system as EMAILJAVA-33455 for investigation by our development team. I will write back here as soon as some feedback is received in this regard. .

Hi Ying,


These two issues seem to be different than that of current thread. Please always create new thread for different issues as it helps us following the thread properly. Also if you need to send large text like in the above post, please send it as text file attachment rather than pasting whole text in the thread. In this way the readability of the thread can be enhanced for better tracking.

Regarding the concurrent threads issue, it is already logged and has been resolved in our new release due in couple of days. You may please test this scenario with our upcoming release Aspose.Email for Java 5.0.0 and let us know the feedback in a separate thread if required.

For the second issue where you are facing problem in conversion of EML to MSG, please create a new thread and provide us sample EML files against each issue for our analysis here. We will try our best to provide assistance as soon as we get the sample files and re-produce the scenario.



The issues you have found earlier (filed as EMAILJAVA-33455;EMAILJAVA-33455) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.