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

Free Support Forum - aspose.com

Message flags

Hi,

How can I set message flag that marks message as not read ?

Thanks

Hi,

Thank you for contacting support.

Messages can be set to read/unread using setMessageFlag( ) function with argument ~MapiMessageFlags.MSGFLAG_READ for un-read messages and without ~ operator for marking the message as read. Could you please give a try to the following sample code which demonstrates this feature and provide your feedback?


String pstFile = “TestPST.pst”;

String folderName = “Issue”;

PersonalStorage pst = PersonalStorage.create(pstFile, FileFormatVersion.Unicode);

pst.getRootFolder().addSubFolder(folderName);

FolderInfo outfolder = pst.getRootFolder().getSubFolder(folderName);


MapiMessage mapimsg = new MapiMessage("from@domain.com", "to@domain.com", “subject 1”, “body”);

mapimsg.setMessageFlags(~MapiMessageFlags.MSGFLAG_READ);

outfolder.addMessage(mapimsg);


mapimsg = new MapiMessage("from@domain.com", "to@domain.com", “subject 2”, “body”);

mapimsg.setMessageFlags(MapiMessageFlags.MSGFLAG_READ);

outfolder.addMessage(mapimsg);


mapimsg = new MapiMessage("from@domain.com", "to@domain.com", “subject 3”, “body”);

mapimsg.setMessageFlags(~MapiMessageFlags.MSGFLAG_READ);

outfolder.addMessage(mapimsg);

Thanks, it’s working.

Hi,

Is there any chance that starting from one of the last versions read flag is working as “negative” ?
I didn’t change my code (but may be it was originally wrong :slight_smile: ) but every mail that I add to the pst as seen marked as not seen (read) and vice versa, here my code (flgas is java mail Flags)

MailMessage eml = MailMessage.load(emlPath);

MapiMessage mapi = MapiMessage.fromMailMessage(eml, OutlookMessageFormat.Unicode);

if(flags != null) {

if(!flags.contains(Flag.SEEN)) {

mapi.setMessageFlags(mapi.getFlags() | MapiMessageFlags.MSGFLAG_READ);

} else {

mapi.setMessageFlags(mapi.getFlags() & ~MapiMessageFlags.MSGFLAG_READ);

}

}


Thanks

Hi,


I have analyzed your code and found that command to set flag for READ/UNREAD is working fine and you may verify it by running both the statements separately under known conditions. It seems that code for checking the condition needs more attention and if issue is not resolved yet, please send us the complete code including the Flags enumerator and compilable code to re-produce the scenario here.