⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rcptcmdhandler.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }            if (session.isAuthRequired() && !session.isRelayingAllowed()) {                // Make sure the mail is being sent locally if not                // authenticated else reject.                if (session.getUser() == null) {                    String toDomain = recipientAddress.getHost();                    if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {                        responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Authentication Required";                        session.writeResponse(responseString);                        StringBuffer sb = new StringBuffer(128);                        sb.append("Rejected message - authentication is required for mail request");                        sb.append(getContext(session,recipientAddress,recipient));                        getLogger().error(sb.toString());                        return;                    }                } else {                    // Identity verification checking                    if (session.getConfigurationData().isVerifyIdentity()) {                        String authUser = (session.getUser()).toLowerCase(Locale.US);                        MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);                        if ((senderAddress == null) || (!authUser.equals(senderAddress.getUser())) ||                            (!session.getConfigurationData().getMailServer().isLocalServer(senderAddress.getHost()))) {                            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Incorrect Authentication for Specified Email Address";                            session.writeResponse(responseString);                            if (getLogger().isErrorEnabled()) {                                StringBuffer errorBuffer =                                    new StringBuffer(128)                                        .append("User ")                                        .append(authUser)                                        .append(" authenticated, however tried sending email as ")                                        .append(senderAddress)                                        .append(getContext(session,recipientAddress,recipient));                                getLogger().error(errorBuffer.toString());                            }                            return;                        }                    }                }            } else if (!session.isRelayingAllowed()) {                String toDomain = recipientAddress.getHost();                if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {                    responseString = "550 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Requested action not taken: relaying denied";                    session.writeResponse(responseString);                    StringBuffer errorBuffer = new StringBuffer(128)                        .append("Rejected message - ")                        .append(session.getRemoteIPAddress())                        .append(" not authorized to relay to ")                        .append(toDomain)                        .append(getContext(session,recipientAddress,recipient));                    getLogger().error(errorBuffer.toString());                    return;                }            }            if (rcptOptionString != null) {              StringTokenizer optionTokenizer = new StringTokenizer(rcptOptionString, " ");              while (optionTokenizer.hasMoreElements()) {                  String rcptOption = optionTokenizer.nextToken();                  int equalIndex = rcptOption.indexOf('=');                  String rcptOptionName = rcptOption;                  String rcptOptionValue = "";                  if (equalIndex > 0) {                      rcptOptionName = rcptOption.substring(0, equalIndex).toUpperCase(Locale.US);                      rcptOptionValue = rcptOption.substring(equalIndex + 1);                  }                  // Unexpected option attached to the RCPT command                  if (getLogger().isDebugEnabled()) {                      StringBuffer debugBuffer =                          new StringBuffer(128)                              .append("RCPT command had unrecognized/unexpected option ")                              .append(rcptOptionName)                              .append(" with value ")                              .append(rcptOptionValue)                              .append(getContext(session,recipientAddress,recipient));                      getLogger().debug(debugBuffer.toString());                  }              }              optionTokenizer = null;            }                        // check if we should check for max recipients            if (maxRcpt > 0) {                int rcptCount = 0;                            // check if the key exists                rcptCount = getRcptCount(session);                                rcptCount++;                        // check if the max recipients has reached                if (rcptCount > maxRcpt) {                    maxRcptReached = true;                    responseString = "452 "+DSNStatus.getStatus(DSNStatus.NETWORK,DSNStatus.DELIVERY_TOO_MANY_REC)+" Requested action not taken: max recipients reached";                    session.writeResponse(responseString);                    getLogger().error(responseString);                }                                // put the recipient cound in session hashtable                session.getState().put(RCPTCOUNT,Integer.toString(rcptCount));            }                        // check if we should use tarpit            if (tarpitRcptCount > 0) {                int rcptCount = 0;                rcptCount = getRcptCount(session);                rcptCount++;                                if (rcptCount > tarpitRcptCount) {                    useTarpit = true;                                   }                                // put the recipient cound in session hashtable                session.getState().put(RCPTCOUNT,Integer.toString(rcptCount));                             }                        if (maxRcptReached == false) {                rcptColl.add(recipientAddress);                session.getState().put(SMTPSession.RCPT_LIST, rcptColl);                responseBuffer.append("250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.ADDRESS_VALID)+" Recipient <")                              .append(recipient)                              .append("> OK");                responseString = session.clearResponseBuffer();                                if (useTarpit == true) {                    try {                        sleep(tarpitSleepTime);                    } catch (InterruptedException e) { }                }                session.writeResponse(responseString);            }        }    }    private String getContext(SMTPSession session, MailAddress recipientAddress, String recipient){        StringBuffer sb = new StringBuffer(128);        if(null!=recipientAddress) {            sb.append(" [to:" + (recipientAddress).toInternetAddress().getAddress() + "]");        } else if(null!=recipient) {            sb.append(" [to:" + recipient + "]");        }        if (null!=session.getState().get(SMTPSession.SENDER)) {            sb.append(" [from:" + ((MailAddress)session.getState().get(SMTPSession.SENDER)).toInternetAddress().getAddress() + "]");        }        return sb.toString();    }             private int getRcptCount(SMTPSession session) {        int startCount = 0;                // check if the key exists        if (session.getState().get(RCPTCOUNT) != null) {            Integer rcptCountInteger = Integer.valueOf(session.getState().get(RCPTCOUNT).toString());            return rcptCountInteger.intValue();        } else {            return startCount;        }    }            public void sleep(float timeInMillis) throws InterruptedException {        Thread.sleep( (long) timeInMillis );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -