예제 #1
0
 public static void all_store(Imap im)
 {
     lock (Imap.all)
         Imap.all.Add(im);
 }
예제 #2
0
        public bool login(
            string dest,
            int port,
            string sslmode,
            string xuser,
            string pass,
            out string result)
        {
            bool flag1 = false;

            if (port == 0)
            {
                port = 143;
            }
            this.host      = dest;
            this.user      = xuser;
            this.last_used = stat.time();
            this.handle    = Imap.global_handle++;
            if (this.cblog != null)
            {
                this.cblog(string.Format("info: Open host {0} port {1} {2}", (object)dest, (object)port, (object)sslmode));
            }
            string reason;

            if (!this.open(dest, port, out reason))
            {
                result = string.Format("Failed to open {0} {1} {2}", (object)dest, (object)port, (object)reason);
                if (this.cblog != null)
                {
                    this.cblog(string.Format("info: {0}", (object)result));
                }
                Imap.last_error = "Open " + dest + " failed " + result;
                return(false);
            }
            Imap.all_store(this);
            if (sslmode == "Implicit SSL")
            {
                if (this.ssl_enable(dest, false))
                {
                    stat.imsg("ssl: implicit ssl started ok");
                    flag1 = true;
                }
                else
                {
                    stat.imsg("ssl: implicit ssl could not start");
                }
            }
            string emsg;

            if (!this.readline(out result, "Login", 300000, out bool _, out emsg))
            {
                this.netclose();
                Imap.last_error = "Open/readline " + dest + " failed " + result + " " + emsg;
                if (this.cblog != null)
                {
                    this.cblog(string.Format("failed: {0}", (object)Imap.last_error));
                }
                return(false);
            }
            this.first_time = true;
            this.cur_folder = "";
            if (sslmode == "Start SSL")
            {
                this.netprintf("starttls\r\n");
                bool flag2 = this.response_wait(out result);
                if (flag2)
                {
                    flag2 = this.ssl_enable(dest, false);
                }
                if (flag2)
                {
                    stat.imsg("ssl: SSL successfully enabled");
                    flag1 = true;
                }
                else
                {
                    stat.imsg("ssl: SSL: Unable to startssl for this connection");
                }
                if (flag2 && this.cblog != null)
                {
                    this.cblog(string.Format("info: SSL started successfully"));
                }
            }
            this.netprintf("login {0} {1}\r\n", (object)this.user, (object)pass);
            bool flag3 = this.response_wait(out result);

            result = stat.trim_eol(result);
            if (flag1)
            {
                result += " +SSL";
            }
            if (!flag3)
            {
                stat.emsg("imap: Login failed {0}", (object)result);
            }
            Imap.last_error = flag3 ? (string)null : "Open " + dest + " failed " + result;
            if (!flag3)
            {
                if (this.cblog != null)
                {
                    this.cblog(string.Format("failed: {0}", (object)Imap.last_error));
                }
            }
            else if (this.cblog != null)
            {
                this.cblog(string.Format("worked: {0}", (object)result));
            }
            return(flag3);
        }