mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 20:11:59 +01:00
Fixed unit tests for sender
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
4b37b4fc1a
commit
58a164467e
@ -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){
|
||||
|
18
src/parser.c
18
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';
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -29,14 +29,14 @@ static void test_parser(struct config *cfg){
|
||||
struct parser_test tests[] = {
|
||||
|
||||
{"1.eml", "<ajahhdddhjdhddh@jatekokbirodalma.hu>", "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", "<OFC1576266.0E8F7B7D-ONC12577CB.00303030-C12577CB.003053CD@hu.ibm.com>", "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", "<list-507327664@mail.aaa.fu>", "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", "<list-507327664@mail.aaa.fu>", "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", "<alpine.LNX.2.00.1209261517040.17054@aaa.fu>", "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", "<av5f1fCf5XO0oBab757826337RSFKvu@pnmarketing.com>", "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", "<list-423974736@mail.aaa.fu>", "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", "<list-507327664@mail.aaa.fu>", "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", "<list-435458392@mail.aaa.fu>", "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", "<list-507327664@mail.aaa.fu>", "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", "<list-435458392@mail.aaa.fu>", "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", "<E1IBifn-0001un-MD@admin4.theregister.co.uk>", "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},
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user