【发布时间】:2016-07-17 17:53:48
【问题描述】:
当我尝试在 C# 中添加命令时,请参阅代码:
private readonly string n = Environment.NewLine;
public string CreateDraft()
{
string output;
string command = "MIME-Version: 1.0" + n +
"From: username@gmail.com" + n +
"To: username@gmail.com" + n +
"Subject: " + machineId + n +
"Content-Type: text/plain; charset=utf-8" + n +
"TESTING" + n;
output = ReceiveResponse("$$ APPEND [Gmail]/Drafts (\\Draft) {" + Encoding.UTF8.GetByteCount(command) + "}" + n);
output += n + ReceiveResponse(command);
return output;
}
private string ReceiveResponse(string command)
{
try
{
if (InternetIsConnected() == true)
{
if (!(tcpc.Connected))
{
Connect();
}
if (tcpc.Connected)
{
dummy = Encoding.ASCII.GetBytes(command);
ssl.Write(dummy, 0, dummy.Length);
ssl.Flush();
response = "";
do
{
bytes = ssl.Read(buffer, 0, buffer.Length);
Decoder decoder = Encoding.UTF8.GetDecoder();
char[] chars = new char[decoder.GetCharCount(buffer, 0, bytes)];
decoder.GetChars(buffer, 0, bytes, chars, 0);
response += new string(chars);
} while (response.Contains("$$") == false && (response.Contains("+") == false));
return response;
}
return "Failure: Terminal Disconnected";
}
}
catch (Exception ex)
{
}
return "Failure";
}
它说,BAD 无法解析命令。它在Encoding.UTF8.GetByteCount(command) 上崩溃,它的长度为 162,但是当我尝试 160 时,它可以工作。 GMAIL 只是不同意我的计数,然后它就停止工作了。
【问题讨论】: