示例#1
0
文件: Server.cs 项目: jsakamoto/bjd5
        protected override string BeforeJob(SockTcp client,List<byte[]> clientBuf)
        {
            Protocol = MailProxyProtocol.Pop3;

            //挨拶文をサーバに変わって送出する
            client.AsciiSend("+OK ");

            //USER コマンドを受け付けるまでループ(最大5回)する
            for(var i=0;i<5;i++) {
                var buf = client.LineRecv(Timeout,this);
                if(buf != null) {
                    var str = Inet.TrimCrlf(Encoding.ASCII.GetString(buf));
                    if(str.ToUpper().IndexOf("USER") == 0) {
                        clientBuf.Add(buf);
                        var tmp = str.Split(' ');
                        if(tmp.Length >= 2) {
                            return tmp[1];//ユーザ名
                        }
                    } else if(str.ToUpper().IndexOf("QUIT") == 0) {
                        return null;
                    } else {
                        client.AsciiSend("-ERR ");
                    }
                }else{
                    Thread.Sleep(300);
                }
            }
            return null;
        }
示例#2
0
文件: Server.cs 项目: jsakamoto/bjd5
        protected override string BeforeJob(SockTcp client,List<byte[]> clientBuf)
        {
            Protocol = MailProxyProtocolKind.Smtp;

            //挨拶文をサーバに変わって送出する
            client.AsciiSend("220 SMTP-Proxy");
            while(clientBuf.Count<5) {
                var buf = client.LineRecv(Timeout,this);
                if(buf == null)
                    return null;//タイムアウト

                //Ver5.8.6
                //var str = Inet.TrimCrlf(Encoding.ASCII.GetString(buf));
                buf = Inet.TrimCrlf(buf);
                var str = Encoding.ASCII.GetString(buf);

                //Ver5,3,4 RESTコマンドは蓄積がプロトコル上できないのでサーバへは送らない
                if(str.ToUpper().IndexOf("RSET")!=0)
                    clientBuf.Add(buf);

                if(str.ToUpper().IndexOf("QUIT") != -1) {
                    return null;
                }
                if(clientBuf.Count > 1) {
                    if(str.ToUpper().IndexOf("MAIL FROM:") != -1) {
                        var mailAddress = str.Substring(str.IndexOf(":") + 1);
                        mailAddress = mailAddress.Trim();
                        mailAddress = mailAddress.Trim(new[] { '<','>' });
                        return mailAddress;//メールアドレス
                    }
                }
                client.AsciiSend("250 OK");
            }
            return null;
        }
示例#3
0
文件: Server.cs 项目: jsakamoto/bjd5
        bool Login(SockTcp sockTcp,ref Pop3LoginState mode,ref MessageList messageList,string user,Ip addr)
        {
            //var folder = Kernel.MailBox.Login(user, addr);
            if(!Kernel.MailBox.Login(user, addr)){
                Logger.Set(LogKind.Secure,sockTcp,1,string.Format("user={0}",user));
                sockTcp.AsciiSend("-ERR Double login");
                return false;
            }
            var folder = string.Format("{0}\\{1}", Kernel.MailBox.Dir, user);
            messageList = new MessageList(folder);//������

            //if (kernel.MailBox.Login(user, addr)) {//POP before SMTP�̂��߂ɁA�Ō�̃��O�C���A�h���X��ۑ�����
            mode = Pop3LoginState.Login;
            Logger.Set(LogKind.Normal,sockTcp,2,string.Format("User {0} from {1}[{2}]",user,sockTcp.RemoteHostname,sockTcp.RemoteAddress.Address));

            // LOGIN
            //dfList = kernel.MailBox.GetDfList(user);
            sockTcp.AsciiSend(string.Format("+OK {0} has {1} message ({2} octets).",user,messageList.Count,messageList.Size));
            return true;
        }
示例#4
0
文件: Server.cs 项目: jsakamoto/bjd5
 void AuthError(SockTcp sockTcp,string user,string pass)
 {
     Logger.Set(LogKind.Secure,sockTcp,3,string.Format("user={0} pass={1}",user,pass));
     // �F�؂̃G���[�͂����ɕԓ���Ԃ��Ȃ�
     var authTimeout = (int)Conf.Get("authTimeout");
     for (int i = 0; i < (authTimeout * 10) && IsLife(); i++) {
         Thread.Sleep(100);
     }
     sockTcp.AsciiSend(string.Format("-ERR Password supplied for {0} is incorrect.",user));
 }
示例#5
0
文件: Data.cs 项目: jsakamoto/bjd5
        //通常はこれを使用する
        public bool Recv(SockTcp sockTcp, int sec,Logger logger, ILife iLife)
        {
            var dtLast = DateTime.Now; //受信が20秒無かった場合は、処理を中断する
            while (iLife.IsLife()){
                if (dtLast.AddSeconds(sec) < DateTime.Now){
                    return false; //タイムアウト
                }
                var len = sockTcp.Length();
                if (len == 0){
                    continue;
                }
                var buf = sockTcp.Recv(len, sec, iLife);
                if (buf == null){
                    return false; //切断された
                }
                dtLast = DateTime.Now;

                var recvStatus = Append(buf);

                if (recvStatus == RecvStatus.Limit){
                    //サイズ制限
                    if (logger != null){
                        logger.Set(LogKind.Secure, sockTcp, 7, string.Format("Limit:{0}KByte", _sizeLimit));
                    }
                    sockTcp.AsciiSend("552 Requested mail action aborted: exceeded storage allocation");
                    return false;
                }
                if (recvStatus == RecvStatus.Finish){
                    return true;
                }
            }
            return false;
        }
示例#6
0
        //string esmtpUser��null�łȂ��ꍇ�ASMTP�F�؂�g�p����
        public SmtpClientResult Send(SockTcp sockTcp,string serverName,Mail mail,MailAddress from,MailAddress to,string authUser,string authPass,ILife iLife)
        {
            var state = State.Ehlo;
            const int timeout = 3;
            var result = SmtpClientResult.Faild;
            //AUTH_STATE authState = AUTH_STATE.LOGIN;

            var smtpAuthClient = new SmtpAuthClient(authUser,authPass);

            LastLog.Clear();//���M���s���̋L�^�̓N���A����

            while (iLife.IsLife()) {
                //********************************************************************
                // �T�[�o����̃��X�|���X�R�[�h(response)��M
                //********************************************************************
                int response;
                //var recvBuf = sockTcp.LineRecv(timeout,OperateCrlf.No,ref life);
                //Ver5.7.3 �^�C���A�E�g���������āA�Ԏ��̒x���T�[�o�ŃG���[�ƂȂ��Ă��܂�
                var recvBuf = sockTcp.LineRecv(timeout+30, iLife);
                if (recvBuf == null) {
                    //���M���s���̍Ō�̑���M�L�^
                    LastLog.Add(sockTcp.LastLineSend);
                    //LastLog.Add(recvStr);
                    break;
                }
                if(recvBuf.Length==0){
                    Thread.Sleep(10);
                    continue;
                }
                recvBuf = Inet.TrimCrlf(recvBuf);//\r\n�̔r��
                var recvStr = Encoding.ASCII.GetString(recvBuf);

                if (state == State.Ehlo) {
                    smtpAuthClient.Ehlo(recvStr);//AUTH�̑Ή��󋵂�擾
                }

                if (recvStr[3] == '-') {
                    //string paramStr = recvStr.Substring(4);
                    continue;
                }
                if (recvStr.IndexOf(' ') == 3) {
                    response = Convert.ToInt32(recvStr.Substring(0, 3));
                } else {
                    //���M���s���̍Ō�̑���M�L�^
                    LastLog.Add(sockTcp.LastLineSend);
                    LastLog.Add(recvStr);
                    break;
                }
                //********************************************************************
                // ��M�������X�|���X�R�[�h(response)�ɂ����(mode)�̕ύX
                //********************************************************************
                if (response == 220) {
                    state = State.Ehlo;
                } else if (response == 221) {
                    if (state == State.Quit)
                        break;
                } else if (response == 250) {
                    if (state == State.Ehlo || state == State.Helo) {
                        state = State.Mail;
                    } else if (state == State.Mail) {
                        state = State.Rcpt;
                    } else if (state == State.Rcpt) {
                        state = State.Data;
                    } else if (state == State.Send) {
                        result = SmtpClientResult.Success;//���M����
                        state = State.Quit;
                    }
                } else if (response == 354) {
                    if (state == State.Data)
                        state = State.Send;
                } else if (response / 100 == 5) {
                    // �]����SMTP�F�؂�K�v�Ƃ��Ȃ��ꍇ�AEHLO�Ɏ��s������HELO�ōĐڑ�����݂�
                    //if (Mode == 1 && TryEhlo && SmtpAuthClient == NULL) {
                    if (state == State.Ehlo) {
                        state = State.Helo;//HELO��500��󂯎�����ꍇ�̓G���[�����ɉ��
                    } else {//���M���s

                        //���M���s���̍Ō�̑���M�L�^
                        LastLog.Add(sockTcp.LastLineSend);
                        LastLog.Add(recvStr);

                        result = SmtpClientResult.ErrorCode;//�G���[�R�[�h��M

                        state = State.Quit;
                    }
                }
                //SMTP�F��
                var ret = smtpAuthClient.Set(recvStr);
                if (ret != null) {
                    sockTcp.AsciiSend(ret);
                    continue;
                }

                //********************************************************************
                // ���(mode)���Ƃ̏���
                //********************************************************************
                if (state == State.Ehlo) {
                    sockTcp.AsciiSend(string.Format("EHLO {0}",serverName));
                }else if (state == State.Helo) {
                    sockTcp.AsciiSend(string.Format("HELO {0}",serverName));
                } else if (state == State.Mail) {
                    //Ver5.0.0-a24
                    //sockTcp.AsciiSend(string.Format("MAIL From:{0}",from),OPERATE_CRLF.YES);
                    sockTcp.AsciiSend(string.Format("MAIL From: <{0}>",from));
                } else if(state == State.Rcpt) {
                    //Ver5.0.0-a24
                    //sockTcp.AsciiSend(string.Format("RCPT To:{0}",to),OPERATE_CRLF.YES);
                    sockTcp.AsciiSend(string.Format("RCPT To: <{0}>",to));
                } else if(state == State.Data) {
                    sockTcp.AsciiSend("DATA");
                } else if (state == State.Send) {
                    if (mail == null) {

                        //���M���s���̍Ō�̑���M�L�^
                        LastLog.Add(sockTcp.LastLineSend);
                        LastLog.Add(recvStr);

                        break;//�G���[����
                    }
                    const int count = -1; //count ���M����{���̍s���i-1�̏ꍇ�͑S���j
                    if (!mail.Send(sockTcp, count)){
                        //_logger.Set(LogKind.Error, null, 9000058, ex.Message);
                        //mail.GetLastError()�𖢏���
                        break;//�G���[����

                    }
                    sockTcp.AsciiSend(".");
                } else if (state == State.Quit) {
                    sockTcp.AsciiSend("QUIT");
                }
            }
            return result;
        }