SmtpParser::Action SmtpParser::parse(SmtpClient *client) { SmtpParser::State last_state; const std::string *cdata; cdata = &client->get_data(); last_state = client->get_last_state(); if (((last_state == SmtpParser::START) || (last_state == SmtpParser::RCPT)) && (helo(client) || mail_from(client) || rcpt_to(client))) { return SmtpParser::OK; } else if (last_state == SmtpParser::RCPT && data(client)) { return SmtpParser::END_DATA; } else if (last_state == SmtpParser::DATA) { parse_mail(client); return SmtpParser::OK; } else if (cdata->compare(0,4,"QUIT") == 0) return SmtpParser::BYE; return SmtpParser::NOT_IMP;; }
static void mime_header_line(MIME_NODE *node) { const HEADER_OPTS *header_info; size_t len = LEN(node->buffer); char *ptr = strrchr(STR(node->buffer), '\n'); if (ptr) { *ptr-- = 0; len--; if (ptr > STR(node->buffer)) { if (*ptr == '\r') { *ptr = 0; len--; } } if (len == 0) return; acl_vstring_truncate(node->buffer, len); } header_info = header_opts_find(STR(node->buffer), node->state->key_buffer); if (header_info) { if (header_info->type == HDR_CONTENT_TYPE) mime_content_type(node, header_info); else if (header_info->type == HDR_CONTENT_TRANSFER_ENCODING) mime_content_encoding(node, header_info); else if (node == node->state->root) { /* 说明邮件头 */ if ((header_info->flags & HDR_OPT_RECIP) && (header_info->flags & HDR_OPT_EXTRACT)) { /* 分析收件人地址: To, Cc, Bcc */ mail_rcpt(node, header_info); } else if ((header_info->flags & HDR_OPT_SENDER)) { /* 分析发件人地址: From, Sender, * Replyto, Returnpath */ mail_from(node, header_info); } else if ((header_info->flags & HDR_OPT_SUBJECT)) { mail_subject(node, header_info); } } else if (header_info->type == HDR_CONTENT_DISPOSITION) { mime_content_disposition(node, header_info); } } if (node->header_list) { HEADER_NV *header = header_split(STR(node->buffer)); if (header) node->header_list->push_back(node->header_list, header); } ACL_VSTRING_RESET(node->buffer); /* 清空缓冲区 */ node->last_ch = 0; node->last_lf = 0; }
bool smtp_client::send_envelope(const mail_message& message) { if (open() == false) return false; if (get_banner() == false) return false; if (greet() == false) return false; const char* user = message.get_auth_user(); const char* pass = message.get_auth_pass(); if (user && pass && auth_login(user, pass) == false) return false; const rfc822_addr* from = message.get_from(); if (from == NULL) { logger_error("from null"); return false; } if (mail_from(from->addr) == false) return false; return to_recipients(message.get_recipients()); }