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

Free Support Forum - aspose.com

Problem reading vCard-files with UTF-8 encoded data

Hello,

When importing contacts from vCard-file format there seems to be an error reading fields with UTF-8 encoded content. I am trying to import and export vCard files with nordic characters and experience problems when the files are imported using Aspose.Email 5.9.1 for .NET.

When saving files with UTF-8 encoded content the nordic characters seem to be exported fine and can be read by Outlook 2016. Hovever when I try to read the same files using the MapiContact.FromVCard method it seems the fields containing UTF-8 information are handled as pure Ansi instead of being UTF-8-decoded.

I have created the following method to reproduce the problem:

private void SaveAndLoadContact()
{
    MapiContact l_createdContact = new MapiContact();
    l_createdContact.NameInfo = new MapiContactNamePropertySet("Frøydis", "Å.", "Lærdal");
    l_createdContact.ProfessionalInfo = new MapiContactProfessionalPropertySet("Åpne Løsninger AS", "Økonomiansvarlig");
    //Save the Contact in VCF format
    l_createdContact.Save(@"D:\Temp\MapiContact.vcf", ContactSaveFormat.VCard);
<span style="color:blue;">var</span> l_contactReadFromFile = <span style="color:#2b91af;">MapiContact</span>.FromVCard(<span style="color:maroon;">@"D:\Temp\MapiContact.vcf"</span>);
<span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">"NameInfo.Title: "</span> + l_contactReadFromFile.NameInfo.DisplayName);
<span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">"NameInfo.GivenName: "</span> + l_contactReadFromFile.NameInfo.GivenName);
<span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">"NameInfo.MiddleName: "</span> + l_contactReadFromFile.NameInfo.MiddleName);
<span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">"NameInfo.Surname: "</span> + l_contactReadFromFile.NameInfo.Surname);
<span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">"ProfessionalInfo.CompanyName: "</span> + l_contactReadFromFile.ProfessionalInfo.CompanyName);
<span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">"ProfessionalInfo.Title: "</span> + l_contactReadFromFile.ProfessionalInfo.Title);

}


which gives the following output on the trace log:

NameInfo.Title: Frøydis Å. Lærdal
NameInfo.GivenName: Frøydis
NameInfo.MiddleName: Ã….
NameInfo.Surname: Lærdal
ProfessionalInfo.CompanyName: Åpne Løsninger AS
ProfessionalInfo.Title: Økonomiansvarlig

As you can see, the encoded characters are not decoded correctly.

Thanks,

Henrik



Hi Henrik,


Thank you for writing to Aspose support team.

I have tested this code and observed the issue. It is logged in our issue tracking system under Id:EMAILNET-35045 for further investigation by the product team. I shall write here as soon as some feedback is received in this regard.
Hello,

and thanks for your response. As this issue is rather urgent for us I wonder if you are aware of any workarounds that could be used in the mean time, for instance if it is possible to manually read the vCard fields or eventually specify a default encoding when reading the file?

thanks, Henrik


Hi Henrik,


We have discussed this issue here and afraid that currently no workaround can be suggested. You may please wait until this issue is analyzed and some response is received by the product team. I shall write here on the forum to share the feedback.

We are sorry for any inconvenience caused to you in this regard.

Hi Henrik,


Could you please give a try to the following sample code and let us know the feedback? Please pay attention where .vcf file is loaded again from the disc using overloaded FromVCard() with Encoding argument.

MapiContact l_createdContact = new MapiContact();<o:p></o:p>

l_createdContact.NameInfo = new MapiContactNamePropertySet("Frøydis", "Å.", "Lærdal");

l_createdContact.ProfessionalInfo = new MapiContactProfessionalPropertySet("Åpne Løsninger AS", "Økonomiansvarlig");

//Save the Contact in VCF format

l_createdContact.Save(@"MapiContact.vcf", ContactSaveFormat.VCard);

//Load the contact again

FileStream fs = new FileStream(@"MapiContact.vcf", FileMode.Open);

var l_contactReadFromFile = MapiContact.FromVCard(fs, Encoding.UTF8);

Console.WriteLine("NameInfo.Title: " + l_contactReadFromFile.NameInfo.DisplayName);

Console.WriteLine("NameInfo.GivenName: " + l_contactReadFromFile.NameInfo.GivenName);

Console.WriteLine("NameInfo.MiddleName: " + l_contactReadFromFile.NameInfo.MiddleName);

Console.WriteLine("NameInfo.Surname: " + l_contactReadFromFile.NameInfo.Surname);

Console.WriteLine("ProfessionalInfo.CompanyName: " + l_contactReadFromFile.ProfessionalInfo.CompanyName);

Console.WriteLine("ProfessionalInfo.Title: " + l_contactReadFromFile.ProfessionalInfo.Title);

Muhammad.Waqas:
Hi Henrik,

Could you please give a try to the following sample code and let us know the feedback? Please pay attention where .vcf file is loaded again from the disc using overloaded FromVCard() with Encoding argument.

MapiContact l_createdContact = new MapiContact();

l_createdContact.NameInfo = new MapiContactNamePropertySet("Frøydis", "Å.", "Lærdal");

l_createdContact.ProfessionalInfo = new MapiContactProfessionalPropertySet("Åpne Løsninger AS", "Økonomiansvarlig");

//Save the Contact in VCF format

l_createdContact.Save(@"MapiContact.vcf", ContactSaveFormat.VCard);

//Load the contact again

FileStream fs = new FileStream(@"MapiContact.vcf", FileMode.Open);

var l_contactReadFromFile = MapiContact.FromVCard(fs, Encoding.UTF8);

Console.WriteLine("NameInfo.Title: " + l_contactReadFromFile.NameInfo.DisplayName);

Console.WriteLine("NameInfo.GivenName: " + l_contactReadFromFile.NameInfo.GivenName);

Console.WriteLine("NameInfo.MiddleName: " + l_contactReadFromFile.NameInfo.MiddleName);

Console.WriteLine("NameInfo.Surname: " + l_contactReadFromFile.NameInfo.Surname);

Console.WriteLine("ProfessionalInfo.CompanyName: " + l_contactReadFromFile.ProfessionalInfo.CompanyName);

Console.WriteLine("ProfessionalInfo.Title: " + l_contactReadFromFile.ProfessionalInfo.Title);

Hello,

and thank you for your assistance. Reading via file stream with specified encoding worked both in the test case I sent you and in the case we discovered in the customer environment.

So again, thanks very much for your help!

-Henrik


Hi Henrik,


Thank you for sharing your feedback. It’s good to know that your issue has been solved. Please feel free to write to us if you have any further query related to the API.

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


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