diff options
| author | zhuzhenjun <[email protected]> | 2024-11-27 08:59:59 +0000 |
|---|---|---|
| committer | zhuzhenjun <[email protected]> | 2024-11-27 08:59:59 +0000 |
| commit | 021d5da694b9e73b01a87a3510c365193371cf52 (patch) | |
| tree | 0ac15411256b78ed81cd6682ae73264c70608759 /decoders/mail/mail_decoder_email.c | |
| parent | 3694c142d974ab35f55bde4a8519525b9afcbc84 (diff) | |
init mail decoderdev-mail-decoder
Diffstat (limited to 'decoders/mail/mail_decoder_email.c')
| -rw-r--r-- | decoders/mail/mail_decoder_email.c | 70 |
1 files changed, 22 insertions, 48 deletions
diff --git a/decoders/mail/mail_decoder_email.c b/decoders/mail/mail_decoder_email.c index d6963a4..ac8ff37 100644 --- a/decoders/mail/mail_decoder_email.c +++ b/decoders/mail/mail_decoder_email.c @@ -843,123 +843,93 @@ struct mail_eml *mail_eml_new(void) return eml; } -int mail_publish_command(struct mail_decoder *env, struct session *sess, +int mail_publish_command(struct mq_runtime *mq, int topic_id, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_command *cmd) { - struct mq_runtime *runtime; struct mail_message *msg; if ((cmd->arg == NULL && cmd->cmd_line == NULL) || (cmd->arg_len == 0 && cmd->cmd_line_len == 0)) { return -1; } - runtime = module_manager_get_mq_runtime(env->mod_mgr_ref); - if (runtime == NULL) { - return -1; - } - msg = (struct mail_message *)calloc(1, sizeof(struct mail_message)); msg->sess_ref = sess; msg->mail_seq = mail_seq; msg->mail_protocol = protocol; msg->command = mail_command_clone(cmd); - mq_runtime_publish_message(runtime, env->command_topic_id, msg); + mq_runtime_publish_message(mq, topic_id, msg); return 0; } -int mail_publish_header(struct mail_decoder *env, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_header *header) +int mail_publish_header(struct mq_runtime *mq, int topic_id, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_header *header) { - struct mq_runtime *runtime; struct mail_message *msg; if (header == NULL || header->n_header_fields == 0) { return -1; } - runtime = module_manager_get_mq_runtime(env->mod_mgr_ref); - if (runtime == NULL) { - return -1; - } - msg = (struct mail_message *)calloc(1, sizeof(struct mail_message)); msg->sess_ref = sess; msg->mail_seq = mail_seq; msg->mail_protocol = protocol; msg->header = header; - mq_runtime_publish_message(runtime, env->header_topic_id, msg); + mq_runtime_publish_message(mq, topic_id, msg); return 0; } -int mail_publish_body(struct mail_decoder *env, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_body *body) +int mail_publish_body(struct mq_runtime *mq, int topic_id, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_body *body) { - struct mq_runtime *runtime; struct mail_message *msg; if (body == NULL || body->body_offset == 0) { return -1; } - runtime = module_manager_get_mq_runtime(env->mod_mgr_ref); - if (runtime == NULL) { - return -1; - } - msg = (struct mail_message *)calloc(1, sizeof(struct mail_message)); msg->sess_ref = sess; msg->mail_seq = mail_seq; msg->mail_protocol = protocol; msg->body = mail_body_clone(body); - mq_runtime_publish_message(runtime, env->body_topic_id, msg); + mq_runtime_publish_message(mq, topic_id, msg); return 0; } -int mail_publish_attachment(struct mail_decoder *env, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_attachment *attachment) +int mail_publish_attachment(struct mq_runtime *mq, int topic_id, struct session *sess, enum MAIL_PROTOCOL protocol, size_t mail_seq, struct mail_attachment *attachment) { - struct mq_runtime *runtime; struct mail_message *msg; if (attachment == NULL || attachment->attachment_name_len == 0 || attachment->attachment_offset == 0) { return -1; } - runtime = module_manager_get_mq_runtime(env->mod_mgr_ref); - if (runtime == NULL) { - return -1; - } - msg = (struct mail_message *)calloc(1, sizeof(struct mail_message)); msg->sess_ref = sess; msg->mail_seq = mail_seq; msg->mail_protocol = protocol; msg->attachment = mail_attachment_clone(attachment); - mq_runtime_publish_message(runtime, env->attachment_topic_id, msg); + mq_runtime_publish_message(mq, topic_id, msg); return 0; } -int mail_publish_eml(struct mail_decoder *env, struct session *sess, enum MAIL_PROTOCOL protocol, struct mail_eml *eml) +int mail_publish_eml(struct mq_runtime *mq, int topic_id, struct session *sess, enum MAIL_PROTOCOL protocol, struct mail_eml *eml) { - struct mq_runtime *runtime; struct mail_message *msg; if (eml == NULL || eml->eml_offset == 0) { return -1; } - runtime = module_manager_get_mq_runtime(env->mod_mgr_ref); - if (runtime == NULL) { - return -1; - } - msg = (struct mail_message *)calloc(1, sizeof(struct mail_message)); msg->sess_ref = sess; msg->mail_protocol = protocol; msg->eml = mail_eml_clone(eml); - mq_runtime_publish_message(runtime, env->eml_topic_id, msg); + mq_runtime_publish_message(mq, topic_id, msg); return 0; } @@ -1313,7 +1283,7 @@ void email_parser_free(struct email_parser *eml_parser) free(eml_parser); } -struct email_parser *email_parser_new(struct mail_decoder *env, enum MAIL_PROTOCOL protocol, int is_c2s) +struct email_parser *email_parser_new(struct mq_runtime *mq, struct mail_topics *topics, enum MAIL_PROTOCOL protocol, int is_c2s) { struct email_parser* eml_parser = NULL; @@ -1346,7 +1316,11 @@ struct email_parser *email_parser_new(struct mail_decoder *env, enum MAIL_PROTOC eml_parser->body = mail_body_new(); eml_parser->current_attachment = mail_attachment_new(); eml_parser->eml = mail_eml_new(); - eml_parser->mail_env_ref = env; + eml_parser->header_topic_id = topics->topic_ids[MAIL_TOPIC_HEADER]; + eml_parser->body_topic_id = topics->topic_ids[MAIL_TOPIC_BODY]; + eml_parser->attachment_topic_id = topics->topic_ids[MAIL_TOPIC_ATTACHMENT]; + eml_parser->eml_topic_id = topics->topic_ids[MAIL_TOPIC_EML]; + eml_parser->mq = mq; return eml_parser; } @@ -1359,7 +1333,7 @@ int email_parser_entry(struct email_parser *eml_parser, struct session *sess, co } else { mail_eml_update(eml_parser->eml, NULL, 0, 1); } - mail_publish_eml(eml_parser->mail_env_ref, sess, eml_parser->protocol, eml_parser->eml); + mail_publish_eml(eml_parser->mq, eml_parser->eml_topic_id, sess, eml_parser->protocol, eml_parser->eml); if (is_eml_header_field(line_type) && eml_parser->header == NULL) { eml_parser->header = mail_header_new(); @@ -1434,11 +1408,11 @@ int email_parser_entry(struct email_parser *eml_parser, struct session *sess, co // body if (eml_parser->MailInfoState == MAIL_GET_COUNT) { mail_body_update(eml_parser->body, eml_parser->mimeinfo->dst, eml_parser->mimeinfo->actLen, 0); - mail_publish_body(eml_parser->mail_env_ref, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->body); + mail_publish_body(eml_parser->mq, eml_parser->body_topic_id, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->body); } if (eml_parser->MailInfoState == MAIL_GET_COUNT_END) { mail_body_update(eml_parser->body, NULL, 0, 1); - mail_publish_body(eml_parser->mail_env_ref, sess, eml_parser->protocol, eml_parser->mail_seq,eml_parser->body); + mail_publish_body(eml_parser->mq, eml_parser->body_topic_id, sess, eml_parser->protocol, eml_parser->mail_seq,eml_parser->body); mail_body_reset(eml_parser->body); } @@ -1450,17 +1424,17 @@ int email_parser_entry(struct email_parser *eml_parser, struct session *sess, co } if (eml_parser->MailInfoState == MAIL_GET_FILECOUNT) { mail_attachment_update(eml_parser->current_attachment, eml_parser->mimeinfo->dst, eml_parser->mimeinfo->actLen, 0); - mail_publish_attachment(eml_parser->mail_env_ref, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->current_attachment); + mail_publish_attachment(eml_parser->mq, eml_parser->attachment_topic_id, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->current_attachment); } if (eml_parser->MailInfoState == MAIL_GET_FILECOUNT_END) { mail_attachment_update(eml_parser->current_attachment, NULL, 0, 1); - mail_publish_attachment(eml_parser->mail_env_ref, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->current_attachment); + mail_publish_attachment(eml_parser->mq, eml_parser->attachment_topic_id, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->current_attachment); mail_attachment_reset(eml_parser->current_attachment); } break; case EML_DATA_HEAD_BODY_BORDER: - mail_publish_header(eml_parser->mail_env_ref, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->header); + mail_publish_header(eml_parser->mq, eml_parser->header_topic_id, sess, eml_parser->protocol, eml_parser->mail_seq, eml_parser->header); eml_parser->header = NULL; eml_parser->EmlAnalyseState = MAIL_STAT_BODY; |
