mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-11-04 02:42:27 +01:00 
			
		
		
		
	code cleanup
This commit is contained in:
		@@ -16,7 +16,7 @@
 | 
				
			|||||||
#include <piler.h>
 | 
					#include <piler.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int store_attachments(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){
 | 
					int store_attachments(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
 | 
				
			||||||
   uint64 id=0;
 | 
					   uint64 id=0;
 | 
				
			||||||
   int i, rc=1, found, affected_rows;
 | 
					   int i, rc=1, found, affected_rows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -145,7 +145,7 @@ struct rule_cond {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _state {
 | 
					struct parser_state {
 | 
				
			||||||
   int line_num;
 | 
					   int line_num;
 | 
				
			||||||
   int message_state;
 | 
					   int message_state;
 | 
				
			||||||
   int is_header;
 | 
					   int is_header;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,7 @@ void remove_xml(char *buf, int *html){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_ZIP
 | 
					#ifdef HAVE_ZIP
 | 
				
			||||||
int extract_opendocument(struct session_data *sdata, struct _state *state, char *filename, char *prefix){
 | 
					int extract_opendocument(struct session_data *sdata, struct parser_state *state, char *filename, char *prefix){
 | 
				
			||||||
   int errorp, i=0, len=0, html=0;
 | 
					   int errorp, i=0, len=0, html=0;
 | 
				
			||||||
   int len2;
 | 
					   int len2;
 | 
				
			||||||
   char buf[MAXBUFSIZE];
 | 
					   char buf[MAXBUFSIZE];
 | 
				
			||||||
@@ -98,7 +98,7 @@ int extract_opendocument(struct session_data *sdata, struct _state *state, char
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int unzip_file(struct session_data *sdata, struct _state *state, char *filename, int *rec, struct __config *cfg){
 | 
					int unzip_file(struct session_data *sdata, struct parser_state *state, char *filename, int *rec, struct __config *cfg){
 | 
				
			||||||
   int errorp, i=0, len=0, fd;
 | 
					   int errorp, i=0, len=0, fd;
 | 
				
			||||||
   char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE];
 | 
					   char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE];
 | 
				
			||||||
   struct zip *z;
 | 
					   struct zip *z;
 | 
				
			||||||
@@ -168,7 +168,7 @@ int unzip_file(struct session_data *sdata, struct _state *state, char *filename,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_TNEF
 | 
					#ifdef HAVE_TNEF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int extract_tnef(struct session_data *sdata, struct _state *state, char *filename, struct __config *cfg){
 | 
					int extract_tnef(struct session_data *sdata, struct parser_state *state, char *filename, struct __config *cfg){
 | 
				
			||||||
   int rc=0, n, rec=1;
 | 
					   int rc=0, n, rec=1;
 | 
				
			||||||
   char tmpdir[BUFLEN], buf[SMALLBUFSIZE];
 | 
					   char tmpdir[BUFLEN], buf[SMALLBUFSIZE];
 | 
				
			||||||
   struct dirent **namelist;
 | 
					   struct dirent **namelist;
 | 
				
			||||||
@@ -215,7 +215,7 @@ void kill_helper(){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void extract_attachment_content(struct session_data *sdata, struct _state *state, char *filename, char *type, int *rec, struct __config *cfg){
 | 
					void extract_attachment_content(struct session_data *sdata, struct parser_state *state, char *filename, char *type, int *rec, struct __config *cfg){
 | 
				
			||||||
   int link[2], n;
 | 
					   int link[2], n;
 | 
				
			||||||
   pid_t pid;
 | 
					   pid_t pid;
 | 
				
			||||||
   char outbuf[MAXBUFSIZE];
 | 
					   char outbuf[MAXBUFSIZE];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
 | 
				
			|||||||
   int rc=ERR, fd;
 | 
					   int rc=ERR, fd;
 | 
				
			||||||
   char *rule;
 | 
					   char *rule;
 | 
				
			||||||
   struct stat st;
 | 
					   struct stat st;
 | 
				
			||||||
   struct _state state;
 | 
					   struct parser_state state;
 | 
				
			||||||
   struct __counters counters;
 | 
					   struct __counters counters;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@
 | 
				
			|||||||
#include <zlib.h>
 | 
					#include <zlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int store_index_data(struct session_data *sdata, struct _state *state, struct __data *data, uint64 id, struct __config *cfg){
 | 
					int store_index_data(struct session_data *sdata, struct parser_state *state, struct __data *data, uint64 id, struct __config *cfg){
 | 
				
			||||||
   int rc=ERR;
 | 
					   int rc=ERR;
 | 
				
			||||||
   char *subj;
 | 
					   char *subj;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -146,7 +146,7 @@ int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int update_metadata_reference(struct session_data *sdata, struct _state *state, struct __data *data, char *ref, struct __config *cfg){
 | 
					int update_metadata_reference(struct session_data *sdata, struct parser_state *state, struct __data *data, char *ref, struct __config *cfg){
 | 
				
			||||||
   int ret = ERR;
 | 
					   int ret = ERR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if(prepare_sql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE, cfg) == ERR) return ret;
 | 
					   if(prepare_sql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE, cfg) == ERR) return ret;
 | 
				
			||||||
@@ -166,7 +166,7 @@ int update_metadata_reference(struct session_data *sdata, struct _state *state,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int store_meta_data(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){
 | 
					int store_meta_data(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
 | 
				
			||||||
   int rc, ret=ERR, result;
 | 
					   int rc, ret=ERR, result;
 | 
				
			||||||
   char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
 | 
					   char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
 | 
				
			||||||
   uint64 id=0;
 | 
					   uint64 id=0;
 | 
				
			||||||
@@ -254,14 +254,14 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __d
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void remove_stripped_attachments(struct _state *state){
 | 
					void remove_stripped_attachments(struct parser_state *state){
 | 
				
			||||||
   int i;
 | 
					   int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   for(i=1; i<=state->n_attachments; i++) unlink(state->attachments[i].internalname);
 | 
					   for(i=1; i<=state->n_attachments; i++) unlink(state->attachments[i].internalname);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int process_message(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){
 | 
					int process_message(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
 | 
				
			||||||
   int rc, fd;
 | 
					   int rc, fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* discard if existing message_id */
 | 
					   /* discard if existing message_id */
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								src/parser.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/parser.c
									
									
									
									
									
								
							@@ -16,12 +16,12 @@
 | 
				
			|||||||
#include <piler.h>
 | 
					#include <piler.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _state parse_message(struct session_data *sdata, int take_into_pieces, struct __data *data, struct __config *cfg){
 | 
					struct parser_state parse_message(struct session_data *sdata, int take_into_pieces, struct __data *data, struct __config *cfg){
 | 
				
			||||||
   FILE *f;
 | 
					   FILE *f;
 | 
				
			||||||
   int i, len;
 | 
					   int i, len;
 | 
				
			||||||
   char *p, buf[MAXBUFSIZE], puf[SMALLBUFSIZE];
 | 
					   char *p, buf[MAXBUFSIZE], puf[SMALLBUFSIZE];
 | 
				
			||||||
   char writebuffer[MAXBUFSIZE], abuffer[MAXBUFSIZE];
 | 
					   char writebuffer[MAXBUFSIZE], abuffer[MAXBUFSIZE];
 | 
				
			||||||
   struct _state state;
 | 
					   struct parser_state state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   init_state(&state);
 | 
					   init_state(&state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,7 +98,7 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void post_parse(struct session_data *sdata, struct _state *state, struct __config *cfg){
 | 
					void post_parse(struct session_data *sdata, struct parser_state *state, struct __config *cfg){
 | 
				
			||||||
   int i, len, rec=0;
 | 
					   int i, len, rec=0;
 | 
				
			||||||
   char *p;
 | 
					   char *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -151,7 +151,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void storno_attachment(struct _state *state){
 | 
					void storno_attachment(struct parser_state *state){
 | 
				
			||||||
   state->has_to_dump = 0;
 | 
					   state->has_to_dump = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if(state->n_attachments <= 0) return;
 | 
					   if(state->n_attachments <= 0) return;
 | 
				
			||||||
@@ -171,7 +171,7 @@ void storno_attachment(struct _state *state){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg){
 | 
					int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg){
 | 
				
			||||||
   char *p, *q, puf[SMALLBUFSIZE];
 | 
					   char *p, *q, puf[SMALLBUFSIZE];
 | 
				
			||||||
   unsigned char b64buffer[MAXBUFSIZE];
 | 
					   unsigned char b64buffer[MAXBUFSIZE];
 | 
				
			||||||
   char tmpbuf[MAXBUFSIZE];
 | 
					   char tmpbuf[MAXBUFSIZE];
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								src/parser.h
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/parser.h
									
									
									
									
									
								
							@@ -9,20 +9,20 @@
 | 
				
			|||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "defs.h"
 | 
					#include "defs.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _state parse_message(struct session_data *sdata, int take_into_pieces, struct __data *data, struct __config *cfg);
 | 
					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 _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 _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg);
 | 
					int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init_state(struct _state *state);
 | 
					void init_state(struct parser_state *state);
 | 
				
			||||||
time_t parse_date_header(char *s, struct __config *cfg);
 | 
					time_t parse_date_header(char *s, struct __config *cfg);
 | 
				
			||||||
int isHexNumber(char *p);
 | 
					int isHexNumber(char *p);
 | 
				
			||||||
int extract_boundary(char *p, struct _state *state);
 | 
					int extract_boundary(char *p, struct parser_state *state);
 | 
				
			||||||
void fixupEncodedHeaderLine(char *buf, int buflen);
 | 
					void fixupEncodedHeaderLine(char *buf, int buflen);
 | 
				
			||||||
void fixupSoftBreakInQuotedPritableLine(char *buf, struct _state *state);
 | 
					void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state);
 | 
				
			||||||
void fixupBase64EncodedLine(char *buf, struct _state *state);
 | 
					void fixupBase64EncodedLine(char *buf, struct parser_state *state);
 | 
				
			||||||
void markHTML(char *buf, struct _state *state);
 | 
					void markHTML(char *buf, struct parser_state *state);
 | 
				
			||||||
int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct _state *state);
 | 
					int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state);
 | 
				
			||||||
void translateLine(unsigned char *p, struct _state *state);
 | 
					void translateLine(unsigned char *p, struct parser_state *state);
 | 
				
			||||||
void fix_email_address_for_sphinx(char *s);
 | 
					void fix_email_address_for_sphinx(char *s);
 | 
				
			||||||
void split_email_address(char *s);
 | 
					void split_email_address(char *s);
 | 
				
			||||||
int does_it_seem_like_an_email_address(char *email);
 | 
					int does_it_seem_like_an_email_address(char *email);
 | 
				
			||||||
@@ -32,7 +32,7 @@ void fixURL(char *url);
 | 
				
			|||||||
int extractNameFromHeaderLine(char *s, char *name, char *resultbuf);
 | 
					int extractNameFromHeaderLine(char *s, char *name, char *resultbuf);
 | 
				
			||||||
char *determine_attachment_type(char *filename, char *type);
 | 
					char *determine_attachment_type(char *filename, char *type);
 | 
				
			||||||
char *get_attachment_extractor_by_filename(char *filename);
 | 
					char *get_attachment_extractor_by_filename(char *filename);
 | 
				
			||||||
void parse_reference(struct _state *state, char *s);
 | 
					void parse_reference(struct parser_state *state, char *s);
 | 
				
			||||||
int base64_decode_attachment_buffer(char *p, int plen, unsigned char *b, int blen);
 | 
					int base64_decode_attachment_buffer(char *p, int plen, unsigned char *b, int blen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* _PARSER_H */
 | 
					#endif /* _PARSER_H */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@
 | 
				
			|||||||
#include "trans.h"
 | 
					#include "trans.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init_state(struct _state *state){
 | 
					void init_state(struct parser_state *state){
 | 
				
			||||||
   int i;
 | 
					   int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   state->message_state = MSG_UNDEF;
 | 
					   state->message_state = MSG_UNDEF;
 | 
				
			||||||
@@ -273,7 +273,7 @@ int isHexNumber(char *p){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int extract_boundary(char *p, struct _state *state){
 | 
					int extract_boundary(char *p, struct parser_state *state){
 | 
				
			||||||
   char *q, *q2;
 | 
					   char *q, *q2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   p += strlen("boundary");
 | 
					   p += strlen("boundary");
 | 
				
			||||||
@@ -326,7 +326,11 @@ int extract_boundary(char *p, struct _state *state){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void fixupEncodedHeaderLine(char *buf, int buflen){
 | 
					void fixupEncodedHeaderLine(char *buf, int buflen){
 | 
				
			||||||
   char *sb, *sq, *p, *q, *r, *s, *e, *start, *end;
 | 
					   char *sb, *sq, *p, *q, *r, *s, *e, *start, *end;
 | 
				
			||||||
   char v[SMALLBUFSIZE], puf[MAXBUFSIZE], encoding[SMALLBUFSIZE], tmpbuf[2*SMALLBUFSIZE];
 | 
					   /*
 | 
				
			||||||
 | 
					    * I thought SMALLBUFSIZE would be enough for v, encoding and tmpbuf(2*),
 | 
				
			||||||
 | 
					    * but then I saw a 6-7000 byte long subject line, so I've switched to MAXBUFSIZE
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					   char v[MAXBUFSIZE], puf[MAXBUFSIZE], encoding[MAXBUFSIZE], tmpbuf[2*MAXBUFSIZE];
 | 
				
			||||||
   int need_encoding, ret;
 | 
					   int need_encoding, ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if(buflen < 5) return;
 | 
					   if(buflen < 5) return;
 | 
				
			||||||
@@ -410,7 +414,7 @@ void fixupEncodedHeaderLine(char *buf, int buflen){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void fixupSoftBreakInQuotedPritableLine(char *buf, struct _state *state){
 | 
					void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){
 | 
				
			||||||
   int i=0;
 | 
					   int i=0;
 | 
				
			||||||
   char *p, puf[MAXBUFSIZE];
 | 
					   char *p, puf[MAXBUFSIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -440,7 +444,7 @@ void fixupSoftBreakInQuotedPritableLine(char *buf, struct _state *state){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void fixupBase64EncodedLine(char *buf, struct _state *state){
 | 
					void fixupBase64EncodedLine(char *buf, struct parser_state *state){
 | 
				
			||||||
   char *p, puf[MAXBUFSIZE];
 | 
					   char *p, puf[MAXBUFSIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if(strlen(state->miscbuf) > 0){
 | 
					   if(strlen(state->miscbuf) > 0){
 | 
				
			||||||
@@ -464,7 +468,7 @@ void fixupBase64EncodedLine(char *buf, struct _state *state){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void markHTML(char *buf, struct _state *state){
 | 
					void markHTML(char *buf, struct parser_state *state){
 | 
				
			||||||
   char *s, puf[MAXBUFSIZE], html[SMALLBUFSIZE];
 | 
					   char *s, puf[MAXBUFSIZE], html[SMALLBUFSIZE];
 | 
				
			||||||
   int k=0, j=0, pos=0;
 | 
					   int k=0, j=0, pos=0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -541,7 +545,7 @@ void markHTML(char *buf, struct _state *state){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct _state *state){
 | 
					int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state){
 | 
				
			||||||
   char *p, html[SMALLBUFSIZE];
 | 
					   char *p, html[SMALLBUFSIZE];
 | 
				
			||||||
   int len;
 | 
					   int len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -579,7 +583,7 @@ int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct _state *state){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void translateLine(unsigned char *p, struct _state *state){
 | 
					void translateLine(unsigned char *p, struct parser_state *state){
 | 
				
			||||||
   int url=0;
 | 
					   int url=0;
 | 
				
			||||||
   int has_url=0;
 | 
					   int has_url=0;
 | 
				
			||||||
   unsigned char prev=' ';
 | 
					   unsigned char prev=' ';
 | 
				
			||||||
@@ -924,7 +928,7 @@ char *get_attachment_extractor_by_filename(char *filename){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void parse_reference(struct _state *state, char *s){
 | 
					void parse_reference(struct parser_state *state, char *s){
 | 
				
			||||||
   int len;
 | 
					   int len;
 | 
				
			||||||
   char puf[SMALLBUFSIZE];
 | 
					   char puf[SMALLBUFSIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								src/piler.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/piler.h
									
									
									
									
									
								
							@@ -37,11 +37,11 @@ void digest_string(char *s, char *digest);
 | 
				
			|||||||
int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg);
 | 
					int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg);
 | 
				
			||||||
int handle_pilerget_request(int new_sd, struct __data *data, struct __config *cfg);
 | 
					int handle_pilerget_request(int new_sd, struct __data *data, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void remove_stripped_attachments(struct _state *state);
 | 
					void remove_stripped_attachments(struct parser_state *state);
 | 
				
			||||||
int process_message(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg);
 | 
					int process_message(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg);
 | 
				
			||||||
int store_file(struct session_data *sdata, char *filename, int startpos, int len, struct __config *cfg);
 | 
					int store_file(struct session_data *sdata, char *filename, int startpos, int len, struct __config *cfg);
 | 
				
			||||||
int remove_stored_message_files(struct session_data *sdata, struct _state *state, struct __config *cfg);
 | 
					int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct __config *cfg);
 | 
				
			||||||
int store_attachments(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg);
 | 
					int store_attachments(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg);
 | 
				
			||||||
int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr, struct __config *cfg);
 | 
					int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct __config read_config(char *configfile);
 | 
					struct __config read_config(char *configfile);
 | 
				
			||||||
@@ -57,9 +57,9 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
 | 
				
			|||||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg);
 | 
					int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg);
 | 
				
			||||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg);
 | 
					int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int store_index_data(struct session_data *sdata, struct _state *state, struct __data *data, uint64 id, struct __config *cfg);
 | 
					int store_index_data(struct session_data *sdata, struct parser_state *state, struct __data *data, uint64 id, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void extract_attachment_content(struct session_data *sdata, struct _state *state, char *filename, char *type, int *rec, struct __config *cfg);
 | 
					void extract_attachment_content(struct session_data *sdata, struct parser_state *state, char *filename, char *type, int *rec, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *dest, struct __config *cfg);
 | 
					int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *dest, struct __config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,7 +80,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
 | 
				
			|||||||
   char s[SMALLBUFSIZE];
 | 
					   char s[SMALLBUFSIZE];
 | 
				
			||||||
   int rc=0;
 | 
					   int rc=0;
 | 
				
			||||||
   uint64 stored_id=0, reindexed=0, delta;
 | 
					   uint64 stored_id=0, reindexed=0, delta;
 | 
				
			||||||
   struct _state state;
 | 
					   struct parser_state state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   delta = to_id - from_id;
 | 
					   delta = to_id - from_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,7 +192,7 @@ struct rule *create_rule_item(struct rule_cond *rule_cond, struct __data *data){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size, int spam){
 | 
					char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int size, int spam){
 | 
				
			||||||
   size_t nmatch=0;
 | 
					   size_t nmatch=0;
 | 
				
			||||||
   struct rule *p;
 | 
					   struct rule *p;
 | 
				
			||||||
   struct node *q;
 | 
					   struct node *q;
 | 
				
			||||||
@@ -249,7 +249,7 @@ char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
time_t query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg){
 | 
					time_t query_retain_period(struct __data *data, struct parser_state *state, int size, int spam, struct __config *cfg){
 | 
				
			||||||
   size_t nmatch=0;
 | 
					   size_t nmatch=0;
 | 
				
			||||||
   struct rule *p;
 | 
					   struct rule *p;
 | 
				
			||||||
   struct node *q;
 | 
					   struct node *q;
 | 
				
			||||||
@@ -317,7 +317,7 @@ time_t query_retain_period(struct __data *data, struct _state *state, int size,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int get_folder_id_by_rule(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg){
 | 
					int get_folder_id_by_rule(struct __data *data, struct parser_state *state, int size, int spam, struct __config *cfg){
 | 
				
			||||||
   size_t nmatch=0;
 | 
					   size_t nmatch=0;
 | 
				
			||||||
   struct rule *p;
 | 
					   struct rule *p;
 | 
				
			||||||
   struct node *q;
 | 
					   struct node *q;
 | 
				
			||||||
@@ -399,7 +399,7 @@ int check_spam_rule(int is_spam, int spam){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int check_attachment_rule(struct _state *state, struct rule *rule){
 | 
					int check_attachment_rule(struct parser_state *state, struct rule *rule){
 | 
				
			||||||
   int i;
 | 
					   int i;
 | 
				
			||||||
   size_t nmatch=0;
 | 
					   size_t nmatch=0;
 | 
				
			||||||
   int ismatch = 0;
 | 
					   int ismatch = 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,12 +10,12 @@
 | 
				
			|||||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table, struct __config *cfg);
 | 
					void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table, struct __config *cfg);
 | 
				
			||||||
int append_rule(struct node *xhash[], struct rule_cond *rule_cond, struct __data *data);
 | 
					int append_rule(struct node *xhash[], struct rule_cond *rule_cond, struct __data *data);
 | 
				
			||||||
struct rule *create_rule_item(struct rule_cond *rule_cond, struct __data *data);
 | 
					struct rule *create_rule_item(struct rule_cond *rule_cond, struct __data *data);
 | 
				
			||||||
char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size, int spam);
 | 
					char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int size, int spam);
 | 
				
			||||||
time_t query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg);
 | 
					time_t query_retain_period(struct __data *data, struct parser_state *state, int size, int spam, struct __config *cfg);
 | 
				
			||||||
int get_folder_id_by_rule(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg);
 | 
					int get_folder_id_by_rule(struct __data *data, struct parser_state *state, int size, int spam, struct __config *cfg);
 | 
				
			||||||
int check_size_rule(int message_size, int size, char *_size);
 | 
					int check_size_rule(int message_size, int size, char *_size);
 | 
				
			||||||
int check_spam_rule(int is_spam, int spam);
 | 
					int check_spam_rule(int is_spam, int spam);
 | 
				
			||||||
int check_attachment_rule(struct _state *state, struct rule *rule);
 | 
					int check_attachment_rule(struct parser_state *state, struct rule *rule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void initrules(struct node *xhash[]);
 | 
					void initrules(struct node *xhash[]);
 | 
				
			||||||
void clearrules(struct node *xhash[]);
 | 
					void clearrules(struct node *xhash[]);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,13 +20,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
					int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			||||||
   int i, ret, pos, n, inj=ERR, state, prevlen=0;
 | 
					   int i, ret, pos, n, inj=ERR, protocol_state, prevlen=0;
 | 
				
			||||||
   char *p, *rcpt, buf[MAXBUFSIZE], puf[MAXBUFSIZE], resp[MAXBUFSIZE], prevbuf[MAXBUFSIZE], last2buf[2*MAXBUFSIZE+1];
 | 
					   char *p, *rcpt, buf[MAXBUFSIZE], puf[MAXBUFSIZE], resp[MAXBUFSIZE], prevbuf[MAXBUFSIZE], last2buf[2*MAXBUFSIZE+1];
 | 
				
			||||||
   char virusinfo[SMALLBUFSIZE], delay[SMALLBUFSIZE], tmpbuf[SMALLBUFSIZE];
 | 
					   char virusinfo[SMALLBUFSIZE], delay[SMALLBUFSIZE], tmpbuf[SMALLBUFSIZE];
 | 
				
			||||||
   char *arule = NULL;
 | 
					   char *arule = NULL;
 | 
				
			||||||
   char *status = NULL;
 | 
					   char *status = NULL;
 | 
				
			||||||
   struct session_data sdata;
 | 
					   struct session_data sdata;
 | 
				
			||||||
   struct _state sstate;
 | 
					   struct parser_state parser_state;
 | 
				
			||||||
   int db_conn=0;
 | 
					   int db_conn=0;
 | 
				
			||||||
   int rc;
 | 
					   int rc;
 | 
				
			||||||
   struct __counters counters;
 | 
					   struct __counters counters;
 | 
				
			||||||
@@ -54,7 +54,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
   srand(getpid());
 | 
					   srand(getpid());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   state = SMTP_STATE_INIT;
 | 
					   protocol_state = SMTP_STATE_INIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   init_session_data(&sdata, cfg);
 | 
					   init_session_data(&sdata, cfg);
 | 
				
			||||||
   sdata.tls = 0;
 | 
					   sdata.tls = 0;
 | 
				
			||||||
@@ -97,7 +97,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
         /* accept mail data */
 | 
					         /* accept mail data */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if(state == SMTP_STATE_DATA){
 | 
					         if(protocol_state == SMTP_STATE_DATA){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* join the last 2 buffer */
 | 
					            /* join the last 2 buffer */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -125,7 +125,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
               if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: got: (.)", sdata.ttmpfile);
 | 
					               if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: got: (.)", sdata.ttmpfile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               state = SMTP_STATE_PERIOD;
 | 
					               protocol_state = SMTP_STATE_PERIOD;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               /* make sure we had a successful read */
 | 
					               /* make sure we had a successful read */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -157,14 +157,14 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
               data->folder = 0;
 | 
					               data->folder = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               sstate = parse_message(&sdata, 1, data, cfg);
 | 
					               parser_state = parse_message(&sdata, 1, data, cfg);
 | 
				
			||||||
               post_parse(&sdata, &sstate, cfg);
 | 
					               post_parse(&sdata, &parser_state, cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               gettimeofday(&tv2, &tz);
 | 
					               gettimeofday(&tv2, &tz);
 | 
				
			||||||
               sdata.__parsed = tvdiff(tv2, tv1);
 | 
					               sdata.__parsed = tvdiff(tv2, tv1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               if(cfg->syslog_recipients == 1){
 | 
					               if(cfg->syslog_recipients == 1){
 | 
				
			||||||
                  rcpt = sstate.b_to;
 | 
					                  rcpt = parser_state.b_to;
 | 
				
			||||||
                  do {
 | 
					                  do {
 | 
				
			||||||
                     rcpt = split_str(rcpt, " ", tmpbuf, sizeof(tmpbuf)-1);
 | 
					                     rcpt = split_str(rcpt, " ", tmpbuf, sizeof(tmpbuf)-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -177,13 +177,13 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
               if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: parsed message", sdata.ttmpfile);
 | 
					               if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: parsed message", sdata.ttmpfile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               if(cfg->archive_only_mydomains == 1 && sdata.internal_sender == 0 && sdata.internal_recipient == 0){
 | 
					               if(cfg->archive_only_mydomains == 1 && sdata.internal_sender == 0 && sdata.internal_recipient == 0){
 | 
				
			||||||
                  remove_stripped_attachments(&sstate);
 | 
					                  remove_stripped_attachments(&parser_state);
 | 
				
			||||||
                  inj = ERR_MYDOMAINS;
 | 
					                  inj = ERR_MYDOMAINS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s\r\n", sdata.ttmpfile);
 | 
					                  snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s\r\n", sdata.ttmpfile);
 | 
				
			||||||
                  write1(new_sd, sdata.acceptbuf, strlen(sdata.acceptbuf), sdata.tls, data->ssl);
 | 
					                  write1(new_sd, sdata.acceptbuf, strlen(sdata.acceptbuf), sdata.tls, data->ssl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  syslog(LOG_PRIORITY, "%s: discarding: not on mydomains, from=%s, message-id=%s", sdata.ttmpfile, sdata.fromemail, sstate.message_id);
 | 
					                  syslog(LOG_PRIORITY, "%s: discarding: not on mydomains, from=%s, message-id=%s", sdata.ttmpfile, sdata.fromemail, parser_state.message_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  goto END_OF_PROCESSING;
 | 
					                  goto END_OF_PROCESSING;
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
@@ -232,20 +232,20 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        /* check message against archiving rules */
 | 
					                        /* check message against archiving rules */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        arule = check_againt_ruleset(data->archiving_rules, &sstate, sdata.tot_len, sdata.spam_message);
 | 
					                        arule = check_againt_ruleset(data->archiving_rules, &parser_state, sdata.tot_len, sdata.spam_message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if(arule){
 | 
					                        if(arule){
 | 
				
			||||||
                           syslog(LOG_PRIORITY, "%s: discarding: archiving policy: *%s*", sdata.ttmpfile, arule);
 | 
					                           syslog(LOG_PRIORITY, "%s: discarding: archiving policy: *%s*", sdata.ttmpfile, arule);
 | 
				
			||||||
                           inj = OK;
 | 
					                           inj = OK;
 | 
				
			||||||
                           counters.c_ignore++;
 | 
					                           counters.c_ignore++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                           remove_stripped_attachments(&sstate);
 | 
					                           remove_stripped_attachments(&parser_state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                           status = S_STATUS_DISCARDED;
 | 
					                           status = S_STATUS_DISCARDED;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else {
 | 
					                        else {
 | 
				
			||||||
                           inj = process_message(&sdata, &sstate, data, cfg);
 | 
					                           inj = process_message(&sdata, &parser_state, data, cfg);
 | 
				
			||||||
                           unlink(sstate.message_id_hash);
 | 
					                           unlink(parser_state.message_id_hash);
 | 
				
			||||||
                           counters.c_size += sdata.tot_len;
 | 
					                           counters.c_size += sdata.tot_len;
 | 
				
			||||||
                           counters.c_stored_size = sdata.stored_len;
 | 
					                           counters.c_stored_size = sdata.stored_len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -274,7 +274,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
                  counters.c_rcvd++;
 | 
					                  counters.c_rcvd++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  if(inj == ERR_EXISTS){
 | 
					                  if(inj == ERR_EXISTS){
 | 
				
			||||||
                     syslog(LOG_PRIORITY, "%s: discarding: duplicate message, id: %llu, message-id: %s", sdata.ttmpfile, sdata.duplicate_id, sstate.message_id);
 | 
					                     syslog(LOG_PRIORITY, "%s: discarding: duplicate message, id: %llu, message-id: %s", sdata.ttmpfile, sdata.duplicate_id, parser_state.message_id);
 | 
				
			||||||
                     counters.c_duplicate++;
 | 
					                     counters.c_duplicate++;
 | 
				
			||||||
                     status = S_STATUS_DUPLICATE;
 | 
					                     status = S_STATUS_DUPLICATE;
 | 
				
			||||||
                  }
 | 
					                  }
 | 
				
			||||||
@@ -283,7 +283,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
 | 
				
			|||||||
                               (sdata.__acquire+sdata.__parsed+sdata.__av+sdata.__compress+sdata.__encrypt+sdata.__store)/1000000.0,
 | 
					                               (sdata.__acquire+sdata.__parsed+sdata.__av+sdata.__compress+sdata.__encrypt+sdata.__store)/1000000.0,
 | 
				
			||||||
                                   sdata.__acquire/1000000.0, sdata.__parsed/1000000.0, sdata.__av/1000000.0, sdata.__compress/1000000.0, sdata.__encrypt/1000000.0, sdata.__store/1000000.0);
 | 
					                                   sdata.__acquire/1000000.0, sdata.__parsed/1000000.0, sdata.__av/1000000.0, sdata.__compress/1000000.0, sdata.__encrypt/1000000.0, sdata.__store/1000000.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  syslog(LOG_PRIORITY, "%s: from=%s, size=%d/%d, attachments=%d, reference=%s, message-id=%s, retention=%d, folder=%d, %s, status=%s", sdata.ttmpfile, sdata.fromemail, sdata.tot_len, sdata.stored_len, sstate.n_attachments, sstate.reference, sstate.message_id, sstate.retention, data->folder, delay, status);
 | 
					                  syslog(LOG_PRIORITY, "%s: from=%s, size=%d/%d, attachments=%d, reference=%s, message-id=%s, retention=%d, folder=%d, %s, status=%s", sdata.ttmpfile, sdata.fromemail, sdata.tot_len, sdata.stored_len, parser_state.n_attachments, parser_state.reference, parser_state.message_id, parser_state.retention, data->folder, delay, status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -343,7 +343,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if(strncasecmp(buf, SMTP_CMD_EHLO, strlen(SMTP_CMD_EHLO)) == 0 || strncasecmp(buf, LMTP_CMD_LHLO, strlen(LMTP_CMD_LHLO)) == 0){
 | 
					         if(strncasecmp(buf, SMTP_CMD_EHLO, strlen(SMTP_CMD_EHLO)) == 0 || strncasecmp(buf, LMTP_CMD_LHLO, strlen(LMTP_CMD_LHLO)) == 0){
 | 
				
			||||||
            if(state == SMTP_STATE_INIT) state = SMTP_STATE_HELO;
 | 
					            if(protocol_state == SMTP_STATE_INIT) protocol_state = SMTP_STATE_HELO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(sdata.tls == 0) snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_250_EXTENSIONS, cfg->hostid, data->starttls);
 | 
					            if(sdata.tls == 0) snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_250_EXTENSIONS, cfg->hostid, data->starttls);
 | 
				
			||||||
            else snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_250_EXTENSIONS, cfg->hostid, "");
 | 
					            else snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_250_EXTENSIONS, cfg->hostid, "");
 | 
				
			||||||
@@ -357,7 +357,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if(strncasecmp(buf, SMTP_CMD_HELO, strlen(SMTP_CMD_HELO)) == 0){
 | 
					         if(strncasecmp(buf, SMTP_CMD_HELO, strlen(SMTP_CMD_HELO)) == 0){
 | 
				
			||||||
            if(state == SMTP_STATE_INIT) state = SMTP_STATE_HELO;
 | 
					            if(protocol_state == SMTP_STATE_INIT) protocol_state = SMTP_STATE_HELO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            strncat(resp, SMTP_RESP_250_OK, MAXBUFSIZE-1);
 | 
					            strncat(resp, SMTP_RESP_250_OK, MAXBUFSIZE-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -378,7 +378,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
                  if(SSL_set_fd(data->ssl, new_sd) == 1){
 | 
					                  if(SSL_set_fd(data->ssl, new_sd) == 1){
 | 
				
			||||||
                     strncat(resp, SMTP_RESP_220_READY_TO_START_TLS, MAXBUFSIZE-1);
 | 
					                     strncat(resp, SMTP_RESP_220_READY_TO_START_TLS, MAXBUFSIZE-1);
 | 
				
			||||||
                     starttls = 1;
 | 
					                     starttls = 1;
 | 
				
			||||||
                     state = SMTP_STATE_INIT;
 | 
					                     protocol_state = SMTP_STATE_INIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                     continue;
 | 
					                     continue;
 | 
				
			||||||
                  } syslog(LOG_PRIORITY, "%s: SSL_set_fd() failed", sdata.ttmpfile);
 | 
					                  } syslog(LOG_PRIORITY, "%s: SSL_set_fd() failed", sdata.ttmpfile);
 | 
				
			||||||
@@ -394,12 +394,12 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
         if(strncasecmp(buf, SMTP_CMD_MAIL_FROM, strlen(SMTP_CMD_MAIL_FROM)) == 0){
 | 
					         if(strncasecmp(buf, SMTP_CMD_MAIL_FROM, strlen(SMTP_CMD_MAIL_FROM)) == 0){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(state != SMTP_STATE_HELO && state != SMTP_STATE_PERIOD){
 | 
					            if(protocol_state != SMTP_STATE_HELO && protocol_state != SMTP_STATE_PERIOD){
 | 
				
			||||||
               strncat(resp, SMTP_RESP_503_ERR, MAXBUFSIZE-1);
 | 
					               strncat(resp, SMTP_RESP_503_ERR, MAXBUFSIZE-1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               if(state == SMTP_STATE_PERIOD){
 | 
					               if(protocol_state == SMTP_STATE_PERIOD){
 | 
				
			||||||
                  if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: initiated new transaction", sdata.ttmpfile);
 | 
					                  if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: initiated new transaction", sdata.ttmpfile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  unlink(sdata.ttmpfile);
 | 
					                  unlink(sdata.ttmpfile);
 | 
				
			||||||
@@ -408,7 +408,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
                  init_session_data(&sdata, cfg);
 | 
					                  init_session_data(&sdata, cfg);
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               state = SMTP_STATE_MAIL_FROM;
 | 
					               protocol_state = SMTP_STATE_MAIL_FROM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               snprintf(sdata.mailfrom, SMALLBUFSIZE-1, "%s\r\n", buf);
 | 
					               snprintf(sdata.mailfrom, SMALLBUFSIZE-1, "%s\r\n", buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -425,7 +425,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
         if(strncasecmp(buf, SMTP_CMD_RCPT_TO, strlen(SMTP_CMD_RCPT_TO)) == 0){
 | 
					         if(strncasecmp(buf, SMTP_CMD_RCPT_TO, strlen(SMTP_CMD_RCPT_TO)) == 0){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(state == SMTP_STATE_MAIL_FROM || state == SMTP_STATE_RCPT_TO){
 | 
					            if(protocol_state == SMTP_STATE_MAIL_FROM || protocol_state == SMTP_STATE_RCPT_TO){
 | 
				
			||||||
               if(strlen(buf) > SMALLBUFSIZE/2){
 | 
					               if(strlen(buf) > SMALLBUFSIZE/2){
 | 
				
			||||||
                  strncat(resp, SMTP_RESP_550_ERR_TOO_LONG_RCPT_TO, MAXBUFSIZE-1);
 | 
					                  strncat(resp, SMTP_RESP_550_ERR_TOO_LONG_RCPT_TO, MAXBUFSIZE-1);
 | 
				
			||||||
                  continue;
 | 
					                  continue;
 | 
				
			||||||
@@ -435,7 +435,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
                  extractEmail(buf, sdata.rcptto[sdata.num_of_rcpt_to]);
 | 
					                  extractEmail(buf, sdata.rcptto[sdata.num_of_rcpt_to]);
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               state = SMTP_STATE_RCPT_TO;
 | 
					               protocol_state = SMTP_STATE_RCPT_TO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
               if(sdata.num_of_rcpt_to < MAX_RCPT_TO-1) sdata.num_of_rcpt_to++;
 | 
					               if(sdata.num_of_rcpt_to < MAX_RCPT_TO-1) sdata.num_of_rcpt_to++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -457,7 +457,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
            inj = ERR;
 | 
					            inj = ERR;
 | 
				
			||||||
            prevlen = 0;
 | 
					            prevlen = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(state != SMTP_STATE_RCPT_TO){
 | 
					            if(protocol_state != SMTP_STATE_RCPT_TO){
 | 
				
			||||||
               strncat(resp, SMTP_RESP_503_ERR, MAXBUFSIZE-1);
 | 
					               strncat(resp, SMTP_RESP_503_ERR, MAXBUFSIZE-1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
@@ -467,7 +467,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
                  strncat(resp, SMTP_RESP_451_ERR, MAXBUFSIZE-1);
 | 
					                  strncat(resp, SMTP_RESP_451_ERR, MAXBUFSIZE-1);
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
               else {
 | 
					               else {
 | 
				
			||||||
                  state = SMTP_STATE_DATA;
 | 
					                  protocol_state = SMTP_STATE_DATA;
 | 
				
			||||||
                  strncat(resp, SMTP_RESP_354_DATA_OK, MAXBUFSIZE-1);
 | 
					                  strncat(resp, SMTP_RESP_354_DATA_OK, MAXBUFSIZE-1);
 | 
				
			||||||
               }
 | 
					               }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -479,7 +479,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
         if(strncasecmp(buf, SMTP_CMD_QUIT, strlen(SMTP_CMD_QUIT)) == 0){
 | 
					         if(strncasecmp(buf, SMTP_CMD_QUIT, strlen(SMTP_CMD_QUIT)) == 0){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            state = SMTP_STATE_FINISHED;
 | 
					            protocol_state = SMTP_STATE_FINISHED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_221_GOODBYE, cfg->hostid);
 | 
					            snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_221_GOODBYE, cfg->hostid);
 | 
				
			||||||
            strncat(resp, buf, MAXBUFSIZE-1);
 | 
					            strncat(resp, buf, MAXBUFSIZE-1);
 | 
				
			||||||
@@ -508,7 +508,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            init_session_data(&sdata, cfg);
 | 
					            init_session_data(&sdata, cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            state = SMTP_STATE_HELO;
 | 
					            protocol_state = SMTP_STATE_HELO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
@@ -550,7 +550,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if(state == SMTP_STATE_FINISHED){
 | 
					      if(protocol_state == SMTP_STATE_FINISHED){
 | 
				
			||||||
         goto QUITTING;
 | 
					         goto QUITTING;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -561,7 +561,7 @@ AFTER_PERIOD:
 | 
				
			|||||||
    * ie. we have timed out than send back 421 error message
 | 
					    * ie. we have timed out than send back 421 error message
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if(state < SMTP_STATE_QUIT && inj == ERR){
 | 
					   if(protocol_state < SMTP_STATE_QUIT && inj == ERR){
 | 
				
			||||||
      snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_421_ERR, cfg->hostid);
 | 
					      snprintf(buf, MAXBUFSIZE-1, SMTP_RESP_421_ERR, cfg->hostid);
 | 
				
			||||||
      write1(new_sd, buf, strlen(buf), sdata.tls, data->ssl);
 | 
					      write1(new_sd, buf, strlen(buf), sdata.tls, data->ssl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -182,7 +182,7 @@ ENDE:
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int remove_stored_message_files(struct session_data *sdata, struct _state *state, struct __config *cfg){
 | 
					int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct __config *cfg){
 | 
				
			||||||
   int i;
 | 
					   int i;
 | 
				
			||||||
   char s[SMALLBUFSIZE];
 | 
					   char s[SMALLBUFSIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ int main(int argc, char **argv){
 | 
				
			|||||||
   int i;
 | 
					   int i;
 | 
				
			||||||
   struct stat st;
 | 
					   struct stat st;
 | 
				
			||||||
   struct session_data sdata;
 | 
					   struct session_data sdata;
 | 
				
			||||||
   struct _state state;
 | 
					   struct parser_state state;
 | 
				
			||||||
   struct __config cfg;
 | 
					   struct __config cfg;
 | 
				
			||||||
   struct __data data;
 | 
					   struct __data data;
 | 
				
			||||||
   struct import import;
 | 
					   struct import import;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user