【问题标题】:IMAP Selecting multi-worded mailboxesIMAP 选择多字邮箱
【发布时间】:2017-09-23 14:04:15
【问题描述】:

我正在尝试在 C# 上创建自己的 Imap 库,到目前为止,我已经能够完成我尝试过的所有操作(连接、登录、列出、选择、获取等)。

但是,我在选择名称中包含多个单词的邮箱时遇到了问题。

例如,邮箱名称“新标签”无法选择,而“收件箱”选择成功。

0002 LIST "" "%"
* LIST (\HasNoChildren) "/" "INBOX"
* LIST (\HasNoChildren) "/" "New"
* LIST (\HasNoChildren) "/" "New Label"
* LIST (\HasChildren \Noselect) "/" "[Gmail]"
0002 OK Success

0003 SELECT INBOX
0003 OK [READ-WRITE] INBOX selected. (Success)

0004 SELECT New Label
0004 BAD Could not parse command

IMAP 规范(RFC 35015.1 邮箱命名)未提及应如何处理。它确实提到了国际命名 5.1.3,但它声明 US-ASCII 可打印字符代表它们自己。

this question 的回答显示邮箱名称应该连同空格一起发送,但这显然不适用于我的情况。

这是我用来创建命令的代码(到目前为止我尝试过的每个命令都可以正常工作):

    public ResponseStatusEnum sendCommandReceiveResponse(out List<String> responseArray, string command, params string[] cmdParams)
    {
        ResponseStatusEnum response;
        if (command == null) throw new Exception("No command passed in to send to the server");
        // Increment the id before getting the id string
        m_nCommandId++;
        StringBuilder sbCommand = new StringBuilder(CommandId + " ");

        // Include the Imap command
        sbCommand.Append(command);

        //Include the parameters specific to the command
        for (int i = 0; i < cmdParams.Length; i++)
        {
            sbCommand.Append(" " + cmdParams[i]);
        }
        sbCommand.Append(ImapEol);

【问题讨论】:

    标签: c# imap


    【解决方案1】:

    RFC 3501 确实指定,第 87 页的第一行指定要使用字符串语法。 Astring 在 IMAP 中用于很多事情,在这种情况下它只是:

    0004 SELECT "New label"
    

    请务必阅读语法中的 astring/string/nstring/literal 产生式,您必须正确使用它们才能在 hello-world 阶段之外解析或生成 IMAP。或者如果你想外包它,可以使用库,C# 上有很好的库。

    【讨论】:

    • 谢谢,在问更多问题之前,我会确保也阅读语法部分。我正在做非常基本的事情(我想熟悉 IMAP),所以我决定不去图书馆。
    • 我以为您可能正在做类似的事情。您可能会发现 Mailkit 的源代码读起来也很有趣,它是 C# 并且写得很好。
    • Fwiw,MailKit的源代码可以在github.com/jstedfast/MailKit找到
    猜你喜欢
    • 2011-07-08
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多