+void init_condition(struct search_condition *condition, char *string) {
+ char full_search_field[TOKEN_BUFFER_SIZE], *search_field;
+ int m;
+
+ string = parse_token(full_search_field, TOKEN_BUFFER_SIZE, ' ', string);
+ search_field = full_search_field;
+
+ if(search_field[0] == '!') {
+ search_field++;
+ condition->negation = 1;
+ } else {
+ condition->negation = 0;
+ }
+
+ /* Last 8 hours */
+
+ if(strcmp(search_field, "8h") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time(0) - 3600 * 8;
+ condition->interval_stop = 0;
+ }
+
+ /* Today and yesterday */
+
+ else if(strcmp(search_field, "24h") == 0 ||
+ strcmp(search_field, "today") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time(0) - 3600 * 24;
+ condition->interval_stop = 0;
+ }
+
+ else if(strcmp(search_field, "yesterday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time(0) - 2 * 3600 * 24;
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ /* Week days */
+
+ else if(strcmp(search_field, "monday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(1);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else if(strcmp(search_field, "tuesday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(2);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else if(strcmp(search_field, "wednesday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(3);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else if(strcmp(search_field, "thursday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(4);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else if(strcmp(search_field, "friday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(5);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else if(strcmp(search_field, "saturday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(6);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else if(strcmp(search_field, "sunday") == 0) {
+ condition->field_id = ID_INTERVAL;
+ condition->interval_start = time_for_past_day(7);
+ condition->interval_stop = condition->interval_start + 3600 * 24;
+ }
+
+ else {
+ condition->field_id = -1;
+
+ for(m = 0; (m < MAX_ID) && condition->field_id == -1; m++) {
+ if(strncmp(field_names[m], search_field, strlen(search_field)) == 0) {
+ condition->field_id = m;
+ }
+ }
+
+ if(condition->field_id == -1) {
+ fprintf(stderr,
+ "mymail: Syntax error in field name \"%s\".\n",
+ search_field);
+ exit(EXIT_FAILURE);
+ }
+
+ if(regcomp(&condition->regexp,
+ string,
+ REG_ICASE)) {
+ fprintf(stderr,
+ "mymail: Syntax error in regexp \"%s\" for field \"%s\".\n",
+ string,
+ field_names[condition->field_id]);
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
+void free_condition(struct search_condition *condition) {
+ if(condition->field_id != ID_INTERVAL) {
+ regfree(&condition->regexp);
+ }
+}
+
+/*********************************************************************/
+/*********************************************************************/
+/*********************************************************************/
+