Attachments are not displayed in pst

Hi
I using aspose 3.5 dll . I am setting few property by addpropertybyTag.
if i set some property then it will not shows the any attachments.


if (Path.GetExtension(f_tmpEmlPath).ToLower() == “.eml”)
{
f_Objmailmessage = MailMessage.Load(f_tmpEmlPath, MessageFormat.Eml);
}

}


f_mapimessage = MapiMessage.FromMailMessage(MailMessage.Load(f_tmpEmlPath, MessageFormat.Eml), OutlookMessageFormat.Unicode);
addByPropertyTag(ref f_mapimessage, p_sysEmail, true);

}


addByPropertyTag(ref f_mapimessage, p_sysEmail, true)
{
try
{
if (p_Messageobj != null && String.IsNullOrEmpty(p_Messageobj.Subject))
{
if (!String.IsNullOrEmpty(p_sysEmail.Subject))
{
f_MapiProperty = new MapiProperty
(MapiPropertyTag.PR_SUBJECT,
f_objEncoding.GetBytes(p_sysEmail.Subject));
p_Messageobj.SetProperty(f_MapiProperty);
f_MapiProperty = null;
}
}
}
catch (Exception ex) { }

}

Hi Maruti,


We regret any inconvenience caused to you in this regard.

However, I am afraid to share that I was not able to make your mentioned code above to compile and run. Could you please provide us a runnable console application that we could use to reproduce this issue at our end and assist you further? Also, please share with us if you face the same issue with the latest version of Aspose.Email for .NET 3.6.0? We’ll look into this and assist you further as soon as possible.

Hi

If i set the unread property then it not display the attachment.


static void TestUnicode()
{


MapiMessage f_mapimessage = null;
PersonalStorage pst = PersonalStorage.Create(@“TestSubject.pst”, FileFormatVersion.Unicode);
FolderInfo f_FolderInfoObj = pst.RootFolder.AddSubFolder(“TestFolder”);
MailMessage p_Messageobj= MailMessage.Load(@“1.eml”, MessageFormat.Eml);
f_mapimessage = MapiMessage.FromMailMessage(p_Messageobj, OutlookMessageFormat.Unicode);

Mail mail=new Mail();
try
{
MapiProperty f_MapiProperty = null;
Encoding f_objEncoding = Encoding.Unicode;

if (!String.IsNullOrEmpty(“This is dummy subject.”))
{
f_MapiProperty = new MapiProperty
(MapiPropertyTag.PR_SUBJECT,
f_objEncoding.GetBytes(“This is dummy subject.”));
f_mapimessage.SetProperty(f_MapiProperty);
f_MapiProperty = null;
}


if (false)
f_mapimessage.SetMessageFlags((f_mapimessage.Flags & ~MapiMessageFlags.MSGFLAG_READ));
else
f_mapimessage.SetMessageFlags((f_mapimessage.Flags & MapiMessageFlags.MSGFLAG_READ));

}
catch (Exception ex) { }

f_FolderInfoObj.AddMessage(f_mapimessage);
pst.Dispose();
}

Hi Maruti,

I have tested this issue with latest version of Aspose.Email for .NET 3.6.0 and the following code sample which has nothing changed in it except some compilation errors removed. The created output PST contains the message in unread form and the attachments are also displayed fine in this PST. Please try it with the latest version of Aspose.Email for .NET and let us know your feedback.

Sample code:

string dir = "EMAIL_514594";
File.Delete(dir + "TestSubject.pst");
MapiMessage f_mapimessage = null;
PersonalStorage pst = PersonalStorage.Create(dir + @"TestSubject.pst", FileFormatVersion.Unicode);
FolderInfo f_FolderInfoObj = pst.RootFolder.AddSubFolder("TestFolder");
MailMessage p_Messageobj = MailMessage.Load(dir + @"att.eml");
f_mapimessage = MapiMessage.FromMailMessage(p_Messageobj, OutlookMessageFormat.Unicode);

try
{
    MapiProperty f_MapiProperty = null;
    Encoding f_objEncoding = Encoding.Unicode;

    if (!String.IsNullOrEmpty("This is dummy subject."))
    {
        f_MapiProperty = new MapiProperty(MapiPropertyTag.PR_SUBJECT, f_objEncoding.GetBytes("This is dummy subject."));
        f_mapimessage.SetProperty(f_MapiProperty);
        f_MapiProperty = null;
    }

    //Set IsRead flag to true
    f_mapimessage.SetMessageFlags((f_mapimessage.Flags | MapiMessageFlags.MSGFLAG_READ));
}
catch (Exception ex) { }

f_FolderInfoObj.AddMessage(f_mapimessage);
pst.Dispose();

Hi
we get issue if we set the read property only. If mail is unread and if we set read property true then we will gate that issue. please change following code you will get issue. or you can connect to my machine via TeamViewer. I will give you remote access.

static void TestUnicode()
{


MapiMessage f_mapimessage = null;
PersonalStorage pst = PersonalStorage.Create(@“TestSubject.pst”, FileFormatVersion.Unicode);
FolderInfo f_FolderInfoObj = pst.RootFolder.AddSubFolder(“TestFolder”);
MailMessage p_Messageobj= MailMessage.Load(@“1.eml”, MessageFormat.Eml);
f_mapimessage = MapiMessage.FromMailMessage(p_Messageobj, OutlookMessageFormat.Unicode);

Mail mail=new Mail();
try
{
MapiProperty f_MapiProperty = null;
Encoding f_objEncoding = Encoding.Unicode;

if (!String.IsNullOrEmpty(“This is dummy subject.”))
{
f_MapiProperty = new MapiProperty
(MapiPropertyTag.PR_SUBJECT,
f_objEncoding.GetBytes(“This is dummy subject.”));
f_mapimessage.SetProperty(f_MapiProperty);
f_MapiProperty = null;
}
f_mapimessage.SetMessageFlags((f_mapimessage.Flags & MapiMessageFlags.MSGFLAG_READ));

}
catch (Exception ex) { }

f_FolderInfoObj.AddMessage(f_mapimessage);
pst.Dispose();
}

Hi Maruti,


The problem arises due to the fact that your are using “&” operator instead of “|” while setting the message flags. This resets all other flags of the message, as SetMessageFlags does not adds this flag but rewrite values in this case, and hence the attachments are not visible in the PST. Please give it a try at your end and let us know your feedback.

Hi
Thank you For giving me asap reply.

By using operator “|” (OR) it is working.
But i have few question

1) When should we use the operator “&”.
2) When should we use the operator “|”.

3) if “&” is not working for read property then how it works with unread property.

4)Why operator “&” is working with 3.2 dll for read property also.

Thank you


Hi Maruti,
Following are the responses to your questions:

1) When should we use the operator "&".

AND(&) should be used when we have to get particular flag and not for setting the flag as done in above sample code.

2) When should we use the operator "|".

OR (|) should be used when we have to set the flag.

3) if "&" is not working for read property then how it works with unread property.
4)Why operator "&" is working with 3.2 dll for read property also.

As discussed above, & cannot be used for setting flag, so you may please use | for setting the flag.

P.S. Above sample code is modified for setting the IsRead flag.