We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception processing email attachments

Hi,

We are getting exceptions when processing email attachments that filenames contain double single quotes at the end (test’’.txt). The exception occurs when the Attachment.Name setter is invoked. The StackTrace appears to indicate the offending filename is resulting in an attempted to find the strings encoding. Double single quotes in the middle of the filename do not cause the exception. Apose.Email for .NET 4.0 version 17.1.0.0.

scrubbedName = FileAndPathNameIllegalCharUtility.CreateSafeFileName(att.Name, out scrubbedName, scrubOptions);

if (scrubbedName.IsNotNullOrEmpty())

{

att.Name = scrubbedName; //Exception here

//Good attachment name add to a list for processing

attachments.Add(att);

}
Characters removed by CreateSafeFileName (URI_ILLEGAL_CHARS = { ‘@’, ‘"’, ‘$’, ‘&’, ‘:’, ‘<’, ‘>’, ‘{’, ‘}’, ‘[’, ‘]’,
‘#’, ‘%’, ‘/’, ‘;’, ‘=’, ‘?’, ‘\’, ‘^’, ‘|’, ‘~’, ‘’’, ‘"’ };

StackTrace-
at

System.Globalization.EncodingTable.internalGetCodePageFromName(String name)<o:p></o:p>

at

System.Globalization.EncodingTable.GetCodePageFromName(String name)<o:p></o:p>

at

System.Text.Encoding.GetEncoding(String name)<o:p></o:p>

at

#=q_60aBNxG2$SuXCZfZj8RxMuQ4QvMCxRRNzSjx5tNaig=.#=qMYQy_hVHueJdS6Pxw7GcW6PqRwLc9ouD2xur1bMlMIg=(String

#=qRIDVWGAM$0BkCBJQsYmZAw==)<o:p></o:p>

at

Aspose.Email.Mime.ContentDisposition.get_FileName()<o:p></o:p>

at

Aspose.Email.Mail.Attachment.#=qjNb7XloW0J8_3iKnFFn9wvb23aHjAydf$MMzPynAANM=(Boolean&

#=qJg7wl47f7hGQvPeIF4FbAsdWdbO_jXQy7EOPmbLH5wM=)<o:p></o:p>

at

Aspose.Email.Mail.Attachment.#=qKmpcowkezBlTXeK44UnmdLVLTH_u7dGPaJWEJTJIVBQ=(String

#=q7G9LZy5KsRJ$RaSgKMwaRg==)<o:p></o:p>

at

Aspose.Email.Mail.Attachment.set_Name(String value)<o:p></o:p>

at

Hyland.Core.SubscriptionServer.Module.CheckForAttachment(MailMessage message,

List`1 attachments, IllegalCharacterScrubOptions scrubOptions) in

M:\TFS\DEV\Core\OnBase.NET\Libraries\Hyland.Core\SubscriptionServer\Module.cs:line

1313<o:p></o:p>

Thank you,
Cameron

Hi Cameron,

Thank you for your inquiry and sharing details.

This is to update you that we have tried to reproduce the issue at our end with the help of information you shared. We are unable to reproduce the issue. Please use the latest version of Aspose.Email for .Net and try again. In case the issue persists, forward the sample project along with details to further look into the issue.

Hi Ikram,


Thank you for the reply. Unfortunately going to 17.4.0.0 did not correct the issue. Please see the attached sample code that produces the error.

Thanks,
Cameron
Hi Cameron,

Thank you for sharing sample project.

This is to update you that we have evaluated the scenario. We used our own server for testing as we were unable to connect to yours. Investigation shows that the sample code is working as expected. We have made a slit change in your code. Following is the new version of the code. Please try this at your end and update us with your feedback.

CODE:

Aspose.Email.Clients.Imap.ImapClient _client = new Aspose.Email.Clients.Imap.ImapClient("xxxx", 993, "xxxx", "xxxx", Aspose.Email.Clients.SecurityOptions.SSLImplicit);
_client.SelectFolder("Inbox2");
Aspose.Email.Clients.Imap.ImapQueryBuilder imapBuilder = new Aspose.Email.Clients.Imap.ImapQueryBuilder();
imapBuilder.HasNoFlags(Aspose.Email.Clients.Imap.ImapMessageFlags.Recent);
Aspose.Email.Tools.Search.MailQuery _query = imapBuilder.GetQuery();
Aspose.Email.Clients.Imap.ImapMessageInfoCollection messageInfos = null;
messageInfos = _client.ListMessages(_query);

Aspose.Email.MailMessage message = null;
if (messageInfos.Count > 0)
{
for (int i = 0; i < messageInfos.Count; i++)
{
Aspose.Email.Clients.Imap.ImapMessageInfo info = messageInfos[i];
message = _client.FetchMessage(info.SequenceNumber);
foreach (Aspose.Email.Attachment att in message.Attachments)
{
att.Name = @"output''.txt"; //Exception generated here
}
}
}

CODE TO CREATE MESSAGE:

Aspose.Email.MailMessage msg = new Aspose.Email.MailMessage("user@domain1.com", "user@domain2.com", "test subject 3", "test message for 3");
Aspose.Email.Attachment attachment;
attachment = new Aspose.Email.Attachment(@"..\output''.txt");
msg.Attachments.Add(attachment);
_client.SubscribeFolder(_client.CurrentFolder.Name);
_client.AppendMessage(_client.CurrentFolder.Name, msg);

Ikram,


Prefacing the string with the @ does not stop the exception. May I ask if your test email contained an attachment with a filename the ends in double single quotes. The exception I am getting references the attachment name not the new name being applied. I can access the filename via (string filename = att.Name) but the call to att.Name = @“output’’.text” generates an exception that references the attachments original name as it appears in the email. TestOneTwo’’.txt it the name of the file as it was attached to the message then sent. As the exception below points out.


System.ArgumentException {"‘TestOneTwo’ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.\r\nParameter name: name"}
This is an Exchange 2016 email server.

Thank you,
Cameron

Hi Cameron,


I have checked the sample code and applied different attachment names containing double single quote at the end, middle and start. It is observed that in all the cases, exception is raised. Could you please confirm, if you are facing the same issue or not? Once the feedback is received, we will discuss the issue here in detail.

Hi Kashif,


Yes I can confirm that is what we are experiencing.

Thank you,
Cameron

Hi Cameron,


Thank you for providing the feedback.

This issue is logged under Id:EMAILNET-38709 for further investigation by the product team. You will be automatically notified once any update is received in this regard.

Thank you Kashif

You are welcome.

The issues you have found earlier (filed as EMAILNET-38709) have been fixed in this update.


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