具有特殊字符的C#Imap Sort命令 [英] C# Imap Sort command with special characters

查看:117
本文介绍了具有特殊字符的C#Imap Sort命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理有关imap排序范围的问题:

I'm working on a problem with imap sort extention:

我的命令如下:

  var query = "icône";
            //byte[] bytes = Encoding.Default.GetBytes(query);
            //query = Encoding.UTF8.GetString(bytes);

            var command = "SORT (REVERSE ARRIVAL) UTF-8 " + "{" + query.Length + "}";
            var imapAnswerString = client.Command(command);
            imapAnswerString = client.Command(query);

我收到以下错误: IMAP命令SORT中的错误错误:原子中有8位数据

I get the following error: BAD Error in IMAP command SORT: 8bit data in atom

我发现了这一点: C#Imap搜索命令带有á,é

但是我没有看到如何准备我的代码以成功发送此请求.

But I don't see how to prepare my code to send this request sucessfully.

推荐答案

非常感谢您的回答.

基本上,MailSystem.net发送请求(Command方法)的方式是此问题的症结所在,而实际上还有一些其他问题.

Basically the way MailSystem.net sends requests (Command method) is the crux of this problem, and some others actually.

命令方法应按以下方式更正:

The command method should be corrected as follows:

首先,将请求发送到imap时,以下代码比原始代码更好:

First, when sending the request to imap, the following code works better than the original one:

 //Convert stuff to have to right encoding in a char array
            var myCommand = stamp + ((stamp.Length > 0) ? " " : "") + command + "\r\n";
            var bytesUtf8 = Encoding.UTF8.GetBytes(myCommand);
            var commandCharArray = Encoding.UTF8.GetString(bytesUtf8).ToCharArray();

#if !PocketPC
            if (this._sslStream != null)
            {


                this._sslStream.Write(System.Text.Encoding.UTF8.GetBytes(commandCharArray));
            }
            else
            {
                base.GetStream().Write(System.Text.Encoding.UTF8.GetBytes(commandCharArray), 0, commandCharArray.Length);
            }
#endif

#if PocketPC
                        base.GetStream().Write(System.Text.Encoding.UTF8.GetBytes(commandCharArray), 0, commandCharArray.Length);
#endif

然后,以相同的方法避免某些死锁或错误的异常,按如下方法改进有效性测试:

Then, in the same method, to avoid some deadlock or wrong exceptions, improve the validity tests as follows:

if (temp.StartsWith(stamp) || temp.ToLower().StartsWith("* " + command.Split(' ')[0].ToLower()) || (temp.StartsWith("+ ") && options.IsPlusCmdAllowed) || temp.Contains("BAD Error in IMAP command"))
                    {
                        lastline = temp;
                        break;
                    }

最后,如果有以下情况,则更新退货:

Finally, update the return if as follows:

if (lastline.StartsWith(stamp + " OK") || temp.ToLower().StartsWith("* " + command.Split(' ')[0].ToLower()) && !options.IsSecondCallCommand || temp.ToLower().StartsWith("* ") && options.IsSecondCallCommand && !temp.Contains("BAD") || temp.StartsWith("+ "))
                return bufferString;

进行此更改后,所有命令都可以正常工作,也可以两次调用命令.与原始代码相比,副作用更少.

With this change, all commands work fine, also double call commands. There are less side effects than with the original code.

这解决了我的大部分问题.

This resolved most of my problems.

这篇关于具有特殊字符的C#Imap Sort命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆