#define BUFFER_SIZE 65536
+char *db_filename;
+char *db_root_path;
+
+int paranoid;
+int action_index;
+
+/********************************************************************/
+
enum {
- ID_MAIL,
+ ID_MAIL = 0,
ID_FROM,
ID_DEST,
ID_SUBJECT,
"part"
};
+/********************************************************************/
+
struct search_request {
int field_id;
int negation;
regex_t regexp;
};
+/********************************************************************/
+
struct parsable_field {
int id;
char *regexp_string;
regex_t regexp;
};
-char *db_filename;
-char *db_root_path;
+static struct parsable_field fields_to_parse[] = {
+ {
+ ID_FROM,
+ "^\\(From \\|[Ff][Rr][Oo][Mm]:\\|[R][r][E][e][P][p][L][l][Y][y]-[T][t][O][o]:\\)",
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+ },
-int paranoid;
-int action_index;
+ {
+ ID_DEST,
+ "^\\([Tt][Oo]\\|[Cc][Cc]\\|[Bb][Cc][Cc]\\): ",
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+
+ {
+ ID_SUBJECT,
+ "^[Ss][Uu][Bb][Jj][Ee][Cc][Tt]: ",
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+
+};
+
+/********************************************************************/
+
+int xor(int a, int b) {
+ return (a && !b) || (!a && b);
+}
char *segment_next_field(char *current) {
while(*current && *current != ' ') current++;
char *mbox_name, *mbox_value;
int mbox_id;
int already_written, m, n;
+ int last_mbox_line_was_empty;
current_position_in_mail = 0;
already_written = 0;
char *position_in_file_string;
char *mail_filename;
- for(n = 0; n < nb_search_patterns &&
- ((hits[n] && !search_requests[n].negation) ||
- (!hits[n] && search_requests[n].negation)); n++);
+ for(n = 0; n < nb_search_patterns && xor(hits[n], search_requests[n].negation); n++);
+
+ /* for(n = 0; n < nb_search_patterns && */
+ /* ((hits[n] && !search_requests[n].negation) || */
+ /* (!hits[n] && search_requests[n].negation)); n++); */
if(n == nb_search_patterns) {
FILE *mail_file;
fseek(mail_file, current_position_in_mail, SEEK_SET);
if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) {
+ last_mbox_line_was_empty = 1;
printf("%s", raw_mbox_line);
- while(fgets(raw_mbox_line, BUFFER_SIZE, mail_file) &&
- strncmp(raw_mbox_line, "From ", 5)) {
+ while(1) {
+ if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
+ (last_mbox_line_was_empty && strncmp(raw_mbox_line, "From ", 5) == 0)) break;
+ last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
printf("%s", raw_mbox_line);
}
}
char raw_mbox_line[BUFFER_SIZE], full_line[BUFFER_SIZE];
char *end_of_full_line;
FILE *file;
- int in_header, new_header;
+ int in_header, new_header, last_mbox_line_was_empty;
unsigned long int position_in_file;
file = fopen(mbox_filename, "r");
position_in_file = 0;
end_of_full_line = 0;
full_line[0] = '\0';
+ last_mbox_line_was_empty = 1;
while(fgets(raw_mbox_line, BUFFER_SIZE, file)) {
- if(strncmp(raw_mbox_line, "From ", 5) == 0) {
+ if(last_mbox_line_was_empty && strncmp(raw_mbox_line, "From ", 5) == 0) {
if(in_header) {
fprintf(stderr,
"Got a ^\"From \" in the header in %s:%lu.\n",
}
in_header = 1;
new_header = 1;
- } else if(strncmp(raw_mbox_line, "\n", 1) == 0) {
+ } else if(raw_mbox_line[0] == '\n') {
if(in_header) { in_header = 0; }
}
+ last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
+
if(in_header) {
if(new_header) {
fprintf(db_file, "mail %lu %s\n", position_in_file, mbox_filename);
{ 0, 0, 0, 0 }
};
-static struct parsable_field fields_to_parse[] = {
- {
- ID_FROM,
- "^\\([Ff][Rr][Oo][Mm]:\\|From\\) *",
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
- },
-
- {
- ID_DEST,
- "^\\([Tt][Oo]\\|[Cc][Cc]\\|[Bb][Cc][Cc]\\): *",
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
- },
-
- {
- ID_SUBJECT,
- "^[Ss][Uu][Bb][Jj][Ee][Cc][Tt]: *",
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
- },
-
-};
-
/*********************************************************************/
int main(int argc, char **argv) {