参数太多在MailSystem.Net使用字符串 [英] Too many arguments using a String in MailSystem.Net

查看:278
本文介绍了参数太多在MailSystem.Net使用字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到使用MailSystem.Net IMAP服务器。直到我尝试使用此代码,它包含一个以上的单词(使用此代码访问任何实际nontest电子邮件,我将要使用它的要求)的密码一切似乎确定。 。在这一点上,我收到一个太多的参数错误登录命令

I'm trying to connect to an IMAP server using MailSystem.Net. everything seems ok until I attempt to use this code with a password that contains more then one word(a requirement for using this code to access any of the actual nontest emails I am going to be using it on). At that point I receive a "too many arguments" error to the login command.

下面的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CommandLine.Utility;
using ActiveUp.Net.Mail;
using PT.MailIntegration.IMAP; // not using this, could be removed



namespace MailP
{
    class Program
    {
        static void Main(string[] args)
        {
            string user = null;
            string password = null;
            string server = null;
            string path = null;

            // this sends the args string into the CommdandLine class and dumps any values into a hashtable
            Arguments CommandLine = new Arguments(args);

            // sets the user
            if (CommandLine["u"] != null)
            {
                user = CommandLine["u"];
            }

            // sets the password
            if (CommandLine["p"] != null)
            {
                password = CommandLine["p"];
            }

            // sets the server
            if (CommandLine["s"] != null)
            {
                server = CommandLine["s"];
            }

            // sets the path
            if (CommandLine["d"] != null)
            {
                @path = CommandLine["d"];
            }

            // program only moves forward as long as it has these 4 arguments
            if ((user != null) &
                (password != null) &
                (server != null) &
                (path != null))
            {
                Imap4Client client = new Imap4Client();
                Console.WriteLine(" " + user + " " + password + " " + server + " " + path);
                client.ConnectSsl(server, 993);
                client.Login(user, password);  //this is where the error pops up
                // this print out means we got in!
                Console.WriteLine("Connection Successful!");

                Mailbox box = client.Mailboxes["inbox"];
                Fetch fetch = box.Fetch;
                int messagesLeft = box.MessageCount;
                int msgIndex = 0;

                while (messagesLeft > 0)
                {
                    msgIndex++;
                    messagesLeft--;
                    Message email = fetch.MessageObject(msgIndex);

                    // if the email has attachments
                    if (email.Attachments.Count > 0)
                    {
                        foreach (MimePart attachment in email.Attachments)
                        {
                            email.Attachments.StoreToFolder(@path);
                            Console.WriteLine("Downloaded!");
                        }
                    }

                    // delete the message using it's UID and position in the mailbox
                    box.UidDeleteMessage(fetch.Uid(msgIndex), true);
                    msgIndex--;
                }

            }
            // this means the user did not enter the expected arguments
            else
            {
                Console.WriteLine("You did not enter the expected data!\n");
                Console.WriteLine("Format should be: ");
                Console.WriteLine("MailP.exe -u <user> -p <password> -s <IMAP SERVER> -d <path>");

                Console.WriteLine("\r\n" + "Press any key to continue...");
                Console.ReadKey(true);

            }
        }
    }
}

对于输入:

mailP.exe -u用户名-password这是我的密码-s
imap.server.com-dC:\downloads

mailP.exe -u "username" -password "this is my password" -s "imap.server.com" -d "c:\downloads"

我得到的错误:

{命令\的登录用户名,这是我的密码\失败:
130312093815354 BAD意外额外的参数来LOGIN\r\ N}

{"Command \"login username this is my password \" failed : 130312093815354 BAD Unexpected extra arguments to LOGIN\r\n"}

我试过铸造密码字符串作为呼叫登录字符串。我也试着具有登录是另一个函数采用两个字符串作为参数的一部分。我猜自己是不是在登录功能也许正确解析引号?如果是,我没能在网上找到另一个人有类似的问题。即使是硬编码密码给出了同样的问题。我完全在这里的损失。我想整个字符串作为参数密码传递。我知道它一定是愚蠢的东西,我已经错过了,但我一直在这个代码向后和我失踪了。

I've tried casting the password string as string in the call to login. I've also tried having the login be part of another function that takes in two strings as arguments. I'm guessing that something isn't parsing the quotes properly in the login function perhaps? If it's that I haven't been able to find another person on the web with a similar issue. Even hard coding the password gives the same issue. I'm totally at a loss here. I want the entire string to be passed in as the argument to password. I know it's got to be something silly that I've missed but I've been over this code backwards and am missing it.

推荐答案

由于密码包含空格,我打赌,你只需用引号将其包围。

Since the password contains spaces, I am betting that you simply have to surround it by quotes.

client.Login(user, "\"" + password + "\"");

这篇关于参数太多在MailSystem.Net使用字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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