Hi,
I faced an issue with custom flags. This issue is reproduced with Aspose.Email for .NET 21.6.
Working with Message Flags on Server | Documentation (aspose.com)
When I try to create flag with ImapMessageFlag.Keyword() it will return more flags than was expected after more than 23 different keywords is created. See log output (CustomKeyword-log.zip (3.3 KB)
) that is generated by code bellow. After 23 different keywords were generated, then ImapMessageFlag.Keyword() will return also “Seen” flag (24: Answered, 25: Flagged, 26: Deleted, …), and therefore HasFlag will return True if message is read at mail server.
Also some strange behavior at with that same 23 log with inf.Flags prints Before and After. Seems like flag is added to messageInfo even tough my code does not add it. If I include now out commented part (AddMessageFlags) then obviously we have an issue as flag
variable can contain not wanted flags and those are added to messages in mail server.
If I remove Guid.NewGuid() part from custom flag then everything works as expected. Seems like generating many different custom flags with Keyword function will overflow to somewhere.
Preconditions in GMail:
- Create folder/label TestFolder
- Send a message to your mail
- Move message to TestFolder
- Read message (to add Seen flag)
ImapClient client = new ImapClient(
"imap.gmail.com", 993, /*add your credentials*/ );
client.CreateConnection( true );
client.SelectFolder( "TestFolder" );
// Repeat 100 times.
for( int i = 1; i <= 100; i++ )
{
// Get messages.
ImapMessageInfoCollection messageInfos = client.ListMessages();
foreach( var inf in messageInfos )
{
Console.WriteLine( $"Before: {inf.Flags}" );
// Create new flag and check if it is in the message.
var flag = ImapMessageFlags.Keyword( $"MyCustomFlag-{Guid.NewGuid()}" );
bool hasFlag = inf.Flags.HasFlag( flag );
Console.WriteLine( $"{i}: {hasFlag}: {flag}" );
Console.WriteLine( $"After: {inf.Flags}" );
Console.WriteLine();
//if( ! hasFlag )
// client.AddMessageFlags( inf.UniqueId, flag );
}
}