How to create special ImapFolders?

+1 vote
asked Jan 10, 2014 by SeToY (520 points)
edited Jan 13, 2014

I'm currently evaluating your Rebex SecureMail suite and found it to be quite useful. Now what I've come across is the use of the special ImapFolders (Inbox, Draft, et cetera).

I can read and tag them just fine in rebex, but how can I set an ImapFolders SpecialUse state, so that I can make a "regular" folder a "drafts" folder, for example?

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Jan 13, 2014 by Tomas Knopp (58,890 points)
edited Jan 13, 2014
 
Best answer

Currently, Rebex Imap client does not offer built-in support for setting the SpecialUse state of an ImapFolder.

However, the task is feasible with Rebex.Net.Imap. Please note that the server has to support the USE parameter of CREATE command. You can check if the server supports it with this code:

imap.SendCommand("CAPABILITY");

ImapResponse response;
response = imap.ReadResponse();

if (!response.GetLines()[0].Parameters.Contains("CREATE-SPECIAL-USE"))
{
    Console.WriteLine("IMAP server does not support the optional USE parameter of the CREATE command.");
    return;
}

/* server supports creating the Special use folder so you can use the Imap.SendCommand and Imap.ReadResponse methods to create a 'MySpecial' IMAP folder with a specified SpecialUses like this:*/

imap.SendCommand("CREATE", "MySpecial", @"(USE (\Drafts \Sent))");
ImapResponse response = imap.ReadResponse();

if (response.Code != ImapResponseCode.Ok)
    throw new ImapException(response);

The above code corresponds to the example from RFC6154, section 5.3. Please note that CREATE-SPECIAL-USE is an optional feature for IMAP server to implement. For more information see the full RFC6154.

commented Jan 13, 2014 by SeToY (520 points)
edited Jan 13, 2014

Thank you! Is that possible to "modify" an existing folder, too? Tried using the "SETMETADATA" command, but it returns "UNKNOWN COMMAND (BAD)".

Also, I tried using the command you posted to create a "Sent" folder.

imapClient.SendCommand("CREATE", "Sent Items", @"(USE (\Sent))");

Result: Code: Bad Description: "CREATE Command requires 1 parameter."

A function to do this out-of-the-box would be nice.

commented Jan 13, 2014 by Tomas Knopp (58,890 points)
edited Jan 13, 2014

Thank you for your suggestion. I have created a new ticket into our system so when we add support for creating SpecialUse IMAP folders into Rebex IMAP component, we will post here to inform you.

As to your question, I have updated my original answer to include a check whether the IMAP server implements the optional CREATE-SPECIAL-USE feature. Your IMAP server response suggests that your IMAP server does not implement it, or it has to be switched on in the server settings.

commented Jan 13, 2014 by Tomas Knopp (58,890 points)
edited Jan 13, 2014

The SETMETADATA command is also not supported by Rebex IMAP out-of-the-box yet. The response "UNKNOWN COMMAND (BAD)" means that your IMAP server does not support the SETMETADATA command either.

...