/********************************************************************/
+struct alias_node {
+ char *alias, *value;
+ struct alias_node *next;
+};
+
+struct alias_node *global_alias_list;
+
+/********************************************************************/
+
struct parsable_field {
int id;
int cflags;
}
}
+/********************************************************************/
+
+void *safe_malloc(size_t n) {
+ void *p = malloc(n);
+ if(!p && n != 0) {
+ fprintf(stderr,
+ "selector: cannot allocate memory: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ return p;
+}
+
FILE *safe_fopen(const char *path, const char *mode, const char *comment) {
FILE *result = fopen(path, mode);
if(result) {
const char *c;
struct tm tm;
+ memset(&tm, 0, sizeof(struct tm));
+
if(db_key == ID_LEADING_LINE) {
c = db_value;
while(*c && *c != ' ') c++; while(*c && *c == ' ') c++;
char full_search_field[TOKEN_BUFFER_SIZE], *search_field;
unsigned int k, m;
const char *string;
+ struct alias_node *a;
string = parse_token(full_search_field, TOKEN_BUFFER_SIZE, ' ', full_string);
search_field = full_search_field;
condition->negation = 0;
}
+ for(a = global_alias_list; a; a = a->next) {
+ if(strcmp(search_field, a->alias) == 0) {
+ search_field = a->value;
+ break;
+ }
+ }
+
condition->db_key = -1;
/* Time condition */
}
}
+const char *eat_space(const char *s) {
+ while(*s == ' ' || *s == '\t') { s++; }
+ return s;
+}
+
+void read_rc_file(const char *rc_filename) {
+ char raw_line[BUFFER_SIZE];
+ char command[TOKEN_BUFFER_SIZE], tmp_token[TOKEN_BUFFER_SIZE];
+
+ FILE *rc_file;
+ int line_number;
+ const char *s;
+ char *t;
+
+ rc_file = fopen(rc_filename, "r");
+
+ if(rc_file) {
+ line_number = 1;
+ while(fgets(raw_line, BUFFER_SIZE, rc_file)) {
+ t = raw_line;
+ while(*t) { if(*t == '\n') { *t = '\0'; }; t++; }
+
+ s = raw_line;
+ s = eat_space(s);
+
+ if(*s && *s != '#') {
+ s = parse_token(command, TOKEN_BUFFER_SIZE, ' ', s);
+ if(strcmp(command, "alias") == 0) {
+ struct alias_node *a = safe_malloc(sizeof(struct alias_node));
+ a->next = global_alias_list;
+ global_alias_list = a;
+ if(s) {
+ s = eat_space(s);
+ s = parse_token(tmp_token, TOKEN_BUFFER_SIZE, '=', s);
+ a->alias = strdup(tmp_token);
+ if(s) {
+ s = eat_space(s);
+ a->value = strdup(s);
+ } else {
+ fprintf(stderr, "%s:%d syntax error, missing alias value.\n",
+ rc_filename,
+ line_number);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ fprintf(stderr, "%s:%d syntax error, missing alias key.\n",
+ rc_filename,
+ line_number);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ fprintf(stderr, "%s:%d syntax error, unknown command '%s'.\n",
+ rc_filename,
+ line_number,
+ command);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ line_number++;
+ }
+ fclose(rc_file);
+ }
+}
+
/*********************************************************************/
/*********************************************************************/
/*********************************************************************/
char *mbox_filename_regexp_string = 0;
char *default_search_field;
char output_filename[PATH_MAX + 1];
+ char rc_filename[PATH_MAX + 1];
int action_index = 0;
int error = 0, show_help = 0;
const unsigned int nb_fields_to_parse =
unsigned int f, n;
unsigned int nb_search_conditions;
struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS];
+ struct alias_node *a, *b;
if(regcomp(&global_leading_from_line_regexp, LEADING_FROM_LINE_REGEXP_STRING, 0)) {
fprintf(stderr,
exit(EXIT_FAILURE);
}
+ if(getenv("MYMAILRC")) {
+ sprintf(rc_filename, "%s", getenv("MYMAILRC"));
+ } else if(getenv("HOME")) {
+ sprintf(rc_filename, "%s/.mymailrc", getenv("HOME"));
+ } else {
+ rc_filename[0] = '\0';
+ }
+
+ global_alias_list = 0;
global_quiet = 0;
global_use_leading_time = 0;
default_search_field = 0;
strncpy(output_filename, "", PATH_MAX);
+ if(rc_filename[0]) {
+ read_rc_file(rc_filename);
+ }
+
setlocale(LC_ALL, "");
nb_search_conditions = 0;
}
}
- fprintf(db_file, "%s version_%s format_%d raw\n", MYMAIL_DB_MAGIC_TOKEN, MYMAIL_VERSION, MYMAIL_DB_FORMAT_VERSION);
+ fprintf(db_file,
+ "%s version_%s format_%d raw\n",
+ MYMAIL_DB_MAGIC_TOKEN,
+ MYMAIL_VERSION,
+ MYMAIL_DB_FORMAT_VERSION);
while(optind < argc) {
recursive_index_mbox(db_file,
free_condition(&search_conditions[n]);
}
+ a = global_alias_list;
+ while(a) {
+ b = a->next;
+ free(a->alias);
+ free(a->value);
+ free(a);
+ a = b;
+ }
+
free(db_filename);
free(db_filename_regexp_string);
free(db_root_path);