From 58a164467e9869baabd413a7c893cd8221b7d571 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Sun, 13 Dec 2020 08:36:12 +0100 Subject: [PATCH] Fixed unit tests for sender Signed-off-by: Janos SUTO --- src/import.c | 2 +- src/parser.c | 18 +++++++++++------- src/parser.h | 2 +- src/piler.c | 2 +- src/reindex.c | 2 +- src/test.c | 2 +- unit_tests/check_attachments.c | 2 +- unit_tests/check_parser.c | 8 ++++---- unit_tests/check_rules.c | 2 +- unit_tests/common.c | 2 +- 10 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/import.c b/src/import.c index c3decf9f..601c9b84 100644 --- a/src/import.c +++ b/src/import.c @@ -71,7 +71,7 @@ int import_message(struct session_data *sdata, struct data *data, struct config sdata->import = 1; state = parse_message(sdata, 1, data, cfg); - post_parse(sdata, data, &state, cfg); + post_parse(sdata, &state, cfg); rule = check_against_ruleset(data->archiving_rules, &state, sdata->tot_len, sdata->spam_message); if(rule){ diff --git a/src/parser.c b/src/parser.c index cd9224b4..dbaa6277 100644 --- a/src/parser.c +++ b/src/parser.c @@ -68,11 +68,21 @@ struct parser_state parse_message(struct session_data *sdata, int take_into_piec add_recipient(data->import->extra_recipient, strlen(data->import->extra_recipient), sdata, &state, data, cfg); } + // If both Sender: and From: headers exist, and they are different, then append + // the From: address to recipients list to give him access to this email as well + + if(state.b_sender_domain[0] && strcmp(state.b_from, state.b_sender)){ + char tmpbuf[SMALLBUFSIZE]; + get_first_email_address_from_string(state.b_from, tmpbuf, sizeof(tmpbuf)); + tmpbuf[strlen(tmpbuf)] = ' '; + add_recipient(tmpbuf, strlen(tmpbuf), sdata, &state, data, cfg); + } + return state; } -void post_parse(struct session_data *sdata, struct data *data, struct parser_state *state, struct config *cfg){ +void post_parse(struct session_data *sdata, struct parser_state *state, struct config *cfg){ int i; clearhash(state->boundaries); @@ -87,12 +97,6 @@ void post_parse(struct session_data *sdata, struct data *data, struct parser_sta if(strlen(state->b_sender) > 255) state->b_sender[255] = '\0'; if(strlen(state->b_sender_domain) > 255) state->b_sender_domain[255] = '\0'; - // TODO: If both Sender: and From: headers exist, and they are different, then - // append the From: address to recipients list to give him access to this email - // as well - - - // Truncate the message_id if it's >255 characters if(strlen(state->message_id) > 255) state->message_id[255] = '\0'; diff --git a/src/parser.h b/src/parser.h index c18bede2..5f536fd7 100644 --- a/src/parser.h +++ b/src/parser.h @@ -10,7 +10,7 @@ #include "defs.h" struct parser_state parse_message(struct session_data *sdata, int take_into_pieces, struct data *data, struct config *cfg); -void post_parse(struct session_data *sdata, struct data *data, struct parser_state *state, struct config *cfg); +void post_parse(struct session_data *sdata, struct parser_state *state, struct config *cfg); int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, unsigned int writebuffersize, char *abuffer, unsigned int abuffersize, struct data *data, struct config *cfg); void init_state(struct parser_state *state); diff --git a/src/piler.c b/src/piler.c index fa49a074..684d90de 100644 --- a/src/piler.c +++ b/src/piler.c @@ -163,7 +163,7 @@ int process_email(char *filename, struct session_data *sdata, struct data *data, parser_state = parse_message(sdata, 1, data, cfg); - post_parse(sdata, data, &parser_state, cfg); + post_parse(sdata, &parser_state, cfg); if(cfg->syslog_recipients == 1){ char *rcpt = parser_state.b_to; diff --git a/src/reindex.c b/src/reindex.c index 812fbe4b..b2b137b4 100644 --- a/src/reindex.c +++ b/src/reindex.c @@ -124,7 +124,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *da snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename); state = parse_message(sdata, 1, data, cfg); - post_parse(sdata, data, &state, cfg); + post_parse(sdata, &state, cfg); rc = store_index_data(sdata, &state, data, stored_id, cfg); diff --git a/src/test.c b/src/test.c index 4d7a8a3f..bbac1891 100644 --- a/src/test.c +++ b/src/test.c @@ -147,7 +147,7 @@ int main(int argc, char **argv){ state = parse_message(&sdata, 1, &data, &cfg); printf("post parsing...\n"); - post_parse(&sdata, &data, &state, &cfg); + post_parse(&sdata, &state, &cfg); printf("message-id: %s / %s\n", state.message_id, state.message_id_hash); printf("from: *%s (%s)*\n", state.b_from, state.b_from_domain); diff --git a/unit_tests/check_attachments.c b/unit_tests/check_attachments.c index f6ee2b1c..e051ea40 100644 --- a/unit_tests/check_attachments.c +++ b/unit_tests/check_attachments.c @@ -43,7 +43,7 @@ static void test_attachments(struct config *cfg){ snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", tests[i].s); state = parse_message(&sdata, 1, &data, cfg); - post_parse(&sdata, &data, &state, cfg); + post_parse(&sdata, &state, cfg); for(j=1; j<=state.n_attachments; j++){ unlink(state.attachments[j].internalname); diff --git a/unit_tests/check_parser.c b/unit_tests/check_parser.c index 9039eb5c..70d53760 100644 --- a/unit_tests/check_parser.c +++ b/unit_tests/check_parser.c @@ -29,14 +29,14 @@ static void test_parser(struct config *cfg){ struct parser_test tests[] = { {"1.eml", "", "játékok birodalma játékbolt hirlevel@jatekokbirodalma.hu hirlevel jatekokbirodalma hu ", "jatekokbirodalma.hu", "", "", "architerv m sj@acts.hu sj acts hu ", "acts.hu ", "", "BLACK FRIDAY - Hihetetlen kedvezmények csak 1 napig november 27-én", 2}, - {"2.eml", "<20151101142653.111156815AF6D@acts.hu>", "jml lighting huixinsoft67@foxmail.com huixinsoft67 foxmail com ", "foxmail.com", "jml lighting hwtwi@mcqw.com hwtwi mcqw com ", "mcqw.com", "sj@acts.hu sj acts hu ", "acts.hu ", "", "New design ultra slim led panel light", 0}, + {"2.eml", "<20151101142653.111156815AF6D@acts.hu>", "jml lighting huixinsoft67@foxmail.com huixinsoft67 foxmail com ", "foxmail.com", "jml lighting hwtwi@mcqw.com hwtwi mcqw com ", "mcqw.com", "sj@acts.hu sj acts hu huixinsoft67@foxmail.com huixinsoft67 foxmail com ", "acts.hu foxmail.com ", "", "New design ultra slim led panel light", 0}, {"5-ibm-images.eml", "", "ibm rendezveny rendezveny@hu.ibm.com rendezveny hu ibm com ", "hu.ibm.com", "marta riman rimanmarta@hu.ibm.com rimanmarta hu ibm com ", "hu.ibm.com", "cim1@aaaa.bbb.fu cim1 aaaa bbb fu ajajaj@piler.aaa.fu ajajaj piler aaa fu ibm rendezveny rendezveny@hu.ibm.com rendezveny hu ibm com ", "aaaa.bbb.fu piler.aaa.fu hu.ibm.com ", "", "***Emlékeztető*** - Egészségipar - eEgészségügy (Út a jövőbe, párbeszéd a gazdaságélénkítésről) 2010. november 4.", 5}, - {"9-attached-text.eml", "", "dr lucky amechi clubzenit@zenithoteles.com clubzenit zenithoteles com ", "zenithoteles.com", "aaa aaa aaa@aaa.fu aaa aaa fu ", "aaa.fu", "usuarios-no-listados ", "", "", "Please read my attached letter", 1}, + {"9-attached-text.eml", "", "dr lucky amechi clubzenit@zenithoteles.com clubzenit zenithoteles com ", "zenithoteles.com", "aaa aaa aaa@aaa.fu aaa aaa fu ", "aaa.fu", "usuarios-no-listados clubzenit@zenithoteles.com clubzenit zenithoteles com ", "zenithoteles.com ", "", "Please read my attached letter", 1}, {"13-xlsx.eml", "", "aaaaa@aaa.fu aaaaa aaa fu ", "aaa.fu", "", "", "sj@acts.hu sj acts hu ", "acts.hu ", "", "ez egy teszt", 1}, {"15-image-only-spam.eml", "", "kriegel paff sketches@pnmarketing.com sketches pnmarketing com ", "pnmarketing.com", "", "", "holmon knobel aaaaa@acts.hu aaaaa acts hu ", "acts.hu ", "", "Lack of concentration, backed up by a vocabulary of tremendous scope, a", 1}, {"16-rfc822-attachment-1.eml", "", "martonagnes martonagnes@lajt.hu martonagnes lajt hu erős istván eistvan@marosheviz.info ", "lajt.hu", "postmaster postmaster@aaa.fu postmaster aaa fu ", "aaa.fu", "martonagnes@lajt.hu martonagnes lajt hu ", "lajt.hu ", "", "Féláras akció! 31000Ft/2fő/3nap húsvétkor is a Park Inn****-ben!", 2 }, - {"17-attached-text-bogus-mime.eml", "", "dr lucky amechi clubzenit@zenithoteles.com clubzenit zenithoteles com ", "zenithoteles.com", "postmaster postmaster@aaa.fu postmaster aaa fu ", "aaa.fu", "usuarios-no-listados ", "", "", "Please read my attached letter", 1}, - {"18-spam-html-encoding.eml", "", "a1 hitelcentrum kft Üveges szilvia a1hitelcentrum@t-online.hu a1hitelcentrum t online hu ", "t-online.hu", "postmaster postmaster@aaa.fu postmaster aaa fu ", "aaa.fu", "postmaster@aaa.fu postmaster aaa fu ", "aaa.fu ", "", "TÁJÉKOZTATÁSVargay Péter", 0}, + {"17-attached-text-bogus-mime.eml", "", "dr lucky amechi clubzenit@zenithoteles.com clubzenit zenithoteles com ", "zenithoteles.com", "postmaster postmaster@aaa.fu postmaster aaa fu ", "aaa.fu", "usuarios-no-listados clubzenit@zenithoteles.com clubzenit zenithoteles com ", "zenithoteles.com ", "", "Please read my attached letter", 1}, + {"18-spam-html-encoding.eml", "", "a1 hitelcentrum kft Üveges szilvia a1hitelcentrum@t-online.hu a1hitelcentrum t online hu ", "t-online.hu", "postmaster postmaster@aaa.fu postmaster aaa fu ", "aaa.fu", "postmaster@aaa.fu postmaster aaa fu a1hitelcentrum@t-online.hu a1hitelcentrum t online hu ", "aaa.fu t-online.hu ", "", "TÁJÉKOZTATÁSVargay Péter", 0}, {"19-pdf-attachment-bad-mime.eml", "<20100213$2b62e942$9cc2b$sxm@61-186.reverse.ukhost4u.com>", "jennifer - billing department billing@limitedsoftwareworld.com billing limitedsoftwareworld com ", "limitedsoftwareworld.com", "", "", "100000 100000@aaa.fu 100000 aaa fu ", "aaa.fu ", "", "Billing Summary for 100000, Processed on 2010-02-13 17:01:03", 1}, {"20-pdf-attachment-bad-mime.eml", "<20100213$2b62e942$9cc2b$sxm@61-187.reverse.ukhost4u.com>", "jennifer - billing department billing@limitedsoftwareworld.com billing limitedsoftwareworld com ", "limitedsoftwareworld.com", "", "", "100000 100000@aaa.fu 100000 aaa fu ", "aaa.fu ", "", "Billing Summary for 100000, Processed on 2010-02-13 17:01:03", 1}, {"21-register-tricky-urls.eml", "", "the register update-49363-08f0f768@list.theregister.co.uk update 49363 08f0f768 list theregister co uk ", "list.theregister.co.uk", "", "", "hello@mail.aaa.fu hello mail aaa fu ", "mail.aaa.fu ", "", "[sp@m] Reg Headlines Friday July 20", 0}, diff --git a/unit_tests/check_rules.c b/unit_tests/check_rules.c index 47d18ca8..4dad5631 100644 --- a/unit_tests/check_rules.c +++ b/unit_tests/check_rules.c @@ -116,7 +116,7 @@ static void test_archiving_rule(struct config *cfg){ snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", rule_test[i].filename); state = parse_message(&sdata, 1, &data, cfg); - post_parse(&sdata, &data, &state, cfg); + post_parse(&sdata, &state, cfg); rule = check_against_ruleset(data.archiving_rules, &state, st.st_size, sdata.spam_message); diff --git a/unit_tests/common.c b/unit_tests/common.c index 3699db36..c75aecdd 100644 --- a/unit_tests/common.c +++ b/unit_tests/common.c @@ -30,7 +30,7 @@ int setup_and_parse_message(struct session_data *sdata, struct parser_state *sta snprintf(sdata->tmpframe, SMALLBUFSIZE-1, "%s.m", filename); *state = parse_message(sdata, 1, data, cfg); - post_parse(sdata, data, state, cfg); + post_parse(sdata, state, cfg); return 0; }