ImapClient.GetMessageFlags with ionos id

Hello there!

I’m using imap.AddMessageFlags(message.Id!, ImapMessageFlags.Seen) to set the flag. However, on the IONOS IMAP server, the Id is not a UUID but something like "someid.@domain". (message is of type MailMessage). This results in the following exception:

System.InvalidOperationException: ‘expected " " instead of .’

If I pass an int for the index of the mail, it works.
It seems the dot (.) or @domain is causing an issue when querying the message. Has anyone encountered this before? Is there a workaround to properly set the message flag from IONOS without using the index, since i don’t have this information?

Thanks in advance!

2 Likes

Hi Pascal,

The "someid.@domain" value is not valid according to specification. Nevertheless, can you try quoting that value? In other words, try using "\"someid.@domain\"".

Does this solve your issue?

If the problem remains, please send us the logs output:

using var imap = new ImapClient(...);

var logger = new StringWriter();
imap.LogOutput = logger;

imap.Connect();
// ...

string output = logger.ToString();

Regards,
Mario

Thanks for the quick answer!

Unfortunately it doesn’t work either.

So my first variant:

imap.AddMessageFlags(message.Id!, ImapMessageFlags.Seen)

this results in the string:

00269198.67EEB1A2@mail.companyName.de

and the logs are:

[2025-04-04 06:25:35] S: * OK [CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL- MOVE NAMESPACE QUOTA SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN AUTH=LOGIN AUTH=PLAIN] IMAP server ready H mieue152 30.2 IMAP-1Mdtui-1tPrnB3Kkg-00amxq
[2025-04-04 06:25:35] C: C00001 AUTHENTICATE PLAIN
[2025-04-04 06:25:35] S: + 
[2025-04-04 06:25:35] C: **********
[2025-04-04 06:25:36] S: C00001 OK AUTHENTICATE completed
[2025-04-04 06:25:36] C: C00002 CAPABILITY
[2025-04-04 06:25:36] S: * CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL- MOVE NAMESPACE QUOTA SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN APPENDLIMIT=140000000
[2025-04-04 06:25:36] S: C00002 OK CAPABILITY completed
[2025-04-04 06:25:36] C: C00003 SELECT "INBOX/LK 2.0"
[2025-04-04 06:25:36] S: * 1 EXISTS
[2025-04-04 06:25:36] S: * 0 RECENT
[2025-04-04 06:25:36] S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
[2025-04-04 06:25:36] S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)] Unlimited
[2025-04-04 06:25:36] S: * OK [UIDNEXT 2] Predicted next UID
[2025-04-04 06:25:36] S: * OK [UIDVALIDITY 1743688335] UIDs valid
[2025-04-04 06:25:36] S: C00003 OK [READ-WRITE] SELECT completed
[2025-04-04 06:25:37] C: C00004 UID STORE 00269198.67EEB1A2@mail.companyName.de:00269198.67EEB1A2@mail.companyName.de +FLAGS.SILENT (\Seen)
[2025-04-04 06:25:37] S: C00004 BAD expected " " instead of .
[2025-04-04 06:25:37] C: C00005 LOGOUT
[2025-04-04 06:25:37] S: * BYE Server logging out
[2025-04-04 06:25:37] S: C00005 OK LOGOUT completed


And my second is:

imap.AddMessageFlags($"\"{message.Id!}\"", ImapMessageFlags.Seen);

This results in unformatted id:

\"00269198.67EEB1A2@mail.companyName.de\"

and formatted:

"00269198.67EEB1A2@mail.companyName.de"

And logs:

[2025-04-04 06:15:19] S: * OK [CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL- MOVE NAMESPACE QUOTA SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN AUTH=LOGIN AUTH=PLAIN] IMAP server ready H mieue109 30.2 IMAP-1MvKjv-1t9Zrs1237-00rvAI
[2025-04-04 06:15:19] C: C00001 AUTHENTICATE PLAIN
[2025-04-04 06:15:19] S: + 
[2025-04-04 06:15:19] C: **********
[2025-04-04 06:15:19] S: C00001 OK AUTHENTICATE completed
[2025-04-04 06:15:19] C: C00002 CAPABILITY
[2025-04-04 06:15:19] S: * CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL- MOVE NAMESPACE QUOTA SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN APPENDLIMIT=140000000
[2025-04-04 06:15:19] S: C00002 OK CAPABILITY completed
[2025-04-04 06:15:19] C: C00003 SELECT "INBOX/LK 2.0"
[2025-04-04 06:15:19] S: * 1 EXISTS
[2025-04-04 06:15:19] S: * 0 RECENT
[2025-04-04 06:15:19] S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
[2025-04-04 06:15:19] S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)] Unlimited
[2025-04-04 06:15:19] S: * OK [UIDNEXT 2] Predicted next UID
[2025-04-04 06:15:19] S: * OK [UIDVALIDITY 1743688335] UIDs valid
[2025-04-04 06:15:19] S: C00003 OK [READ-WRITE] SELECT completed
[2025-04-04 06:15:21] C: C00004 UID STORE "00269198.67EEB1A2@mail.companyName.de":"00269198.67EEB1A2@mail.companyName.de" +FLAGS.SILENT (\Seen)
[2025-04-04 06:15:21] S: C00004 BAD expected DIGIT instead of "\""
[2025-04-04 06:15:21] C: C00005 LOGOUT
[2025-04-04 06:15:21] S: * BYE Server logging out
[2025-04-04 06:15:21] S: C00005 OK LOGOUT completed

I see now what the problem is, you should not be using MailMessage.Id, you should be using ImapMessageInfo.Uid.

Please check our Listing Messages example:

In other words, these two values don’t represent the same thing.

The MailMessage.Id is a globally unique identifier. See the specification of Content-ID Header Field, which applies the same rules to the message’s ID.

On the other hand, the ImapMessageInfo.Uid is unique within a mailbox (a single email account). See the Unique Identifier (UID) Message Attribute.

Ahh it works! Thank you vm! :slight_smile:

Last quick question:

The class ImapMessageInfo has the propery Number, so I guess i can map these instances with the instances of Type MailMessage with this for loop:

imap.SelectFolder(ServiceSettings.InboxFolderIonos, false);
var count = imap.SelectedFolder.Count;

var listMessages = imap.ListMessages();

for (int index= 1; index<= count; index++)
{
  var message = imap.GetMessage(number);
  messages.Add(message); 
// so here I could search in my listMessages where:
// the Number property equals index
}

This should always work, or do i miss something?

If the mailbox is not changed, then yes, the sequence numbers should remain as they were.

1 Like