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,
Thanks!
Do you have an EST on how long it will take to fix this issue?
Best regards,
Ying
Hi Ying,
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,
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.
-
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)
-
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.
-
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
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.com2. From msg file:Expected result, the invalid address was kept.a"xasadf@xam.com is shown as a"xasadf@xam.com in outlook.
billowgy:3. Could not add the invalid address to the header manuallymailMsg.getHeaders().add_("to", "7.abc@\"aaa");
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...............
billowgy:Any update?There are a couple of issues we have with the latest release1. 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.
billowgy:2. Reject invalid content-typeIt will throw exception like: "The specified content type is invalid."Again, we want to keep malformed content-type.3. Reject on wrong attachment structureexception like "Multipart mime document has incorrect structure"
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?
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,
Hi Kashif,
Any update?
Thanks,
Ying
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);
Hi Ying,
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.