Commit e70fd8ad authored by Kim Vandry's avatar Kim Vandry

Don't warn when MH subfolder names look like message names.

Previously, any file in an MH folder with a numeric name was treated as
a message and if it was found to be a direcotry instead of a regular
file (as a subfolder with a numeric name would be), we complained about
it. Now, suppress these warnings.

Fixes rc0/mairix#24 and https://bugs.debian.org/700906
parent 782cea0b
......@@ -916,6 +916,13 @@ static void add_msg_path(struct database *db, char *path, time_t mtime, size_t m
}
/*}}}*/
enum stat_result {/*{{{*/
STAT_RESULT_BAD,
STAT_RESULT_FILE,
STAT_RESULT_DIR,
};
/*}}}*/
static int do_stat(struct msgpath *mp)/*{{{*/
{
struct stat sb;
......@@ -923,17 +930,20 @@ static int do_stat(struct msgpath *mp)/*{{{*/
if (mp->type == MTY_IMAP) {
mp->src.mpf.mtime = 0;
mp->src.mpf.size = 0;
return 1;
return STAT_RESULT_FILE;
}
status = stat(mp->src.mpf.path, &sb);
if ((status < 0) ||
!S_ISREG(sb.st_mode)) {
return 0;
} else {
if (status < 0) {
return STAT_RESULT_BAD;
}
if (S_ISREG(sb.st_mode)) {
mp->src.mpf.mtime = sb.st_mtime;
mp->src.mpf.size = sb.st_size;
return 1;
return STAT_RESULT_FILE;
} else if (S_ISDIR(sb.st_mode)) {
return STAT_RESULT_DIR;
}
return STAT_RESULT_BAD;
}
/*}}}*/
int update_database(struct database *db, struct msgpath *sorted_paths, int n_msgs, int do_fast_index, struct imap_ll *imapc)/*{{{*/
......@@ -951,7 +961,6 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
int matched_index;
int i, new_entries_start_at;
int any_new, n_newly_pruned, n_already_dead;
int status;
file_in_db = new_array(char, n_msgs);
file_in_new_list = new_array(char, db->n_msgs);
......@@ -972,16 +981,18 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
} else {
status = do_stat(sorted_paths + matched_index);
if (status) {
if (sorted_paths[matched_index].src.mpf.mtime == db->msgs[i].src.mpf.mtime) {
/* Treat stale files as though the path has changed. */
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
}
} else {
/* This path will get treated as dead, and be re-stated below.
* When that stat fails, the path won't get added to the db. */
switch (do_stat(sorted_paths + matched_index)) {
case STAT_RESULT_FILE:
if (sorted_paths[matched_index].src.mpf.mtime == db->msgs[i].src.mpf.mtime) {
/* Treat stale files as though the path has changed. */
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
}
break;
default:
/* This path will get treated as dead, and be re-stated below.
* When that stat fails, the path won't get added to the db. */
break;
}
}
}
......@@ -1045,16 +1056,27 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
any_new = 0;
for (i=0; i<n_msgs; i++) {
if (!file_in_db[i]) {
int status;
any_new = 1;
/* The 'sorted_paths' array is only used for file-per-message folders. */
status = do_stat(sorted_paths + i);
if (status) {
/* We only add files that could be successfully stat()'d as regular
* files. */
add_msg_path(db, sorted_paths[i].src.mpf.path, sorted_paths[i].src.mpf.mtime, sorted_paths[i].src.mpf.size, sorted_paths[i].type);
} else {
fprintf(stderr, "Cannot add '%s' to database; stat() failed\n", sorted_paths[i].src.mpf.path);
switch(do_stat(sorted_paths + i)) {
case STAT_RESULT_FILE:
/* We only add files that could be successfully stat()'d as regular
* files. */
add_msg_path(db, sorted_paths[i].src.mpf.path, sorted_paths[i].src.mpf.mtime, sorted_paths[i].src.mpf.size, sorted_paths[i].type);
break;
case STAT_RESULT_DIR:
if (sorted_paths[i].source_ft == FT_MH) {
/* With MH, something that looks like a message but is a
directory is actually a subfolder with a numeric name.
Don't warn about it */
break;
}
/* In all other cases, treat any non-regular-file the same
and warn about it. */
/* fallthrough */
default:
fprintf(stderr, "Cannot add '%s' to database; stat() failed\n", sorted_paths[i].src.mpf.path);
break;
}
}
}
......
......@@ -61,7 +61,7 @@ void free_msgpath_array(struct msgpath_array *x)/*{{{*/
free(x);
}
/*}}}*/
static void add_file_to_list(char *x, struct msgpath_array *arr) {/*{{{*/
static void add_file_to_list(char *x, struct msgpath_array *arr, enum folder_type ft) {/*{{{*/
char *y = new_string(x);
if (arr->n == arr->max) {
arr->max += 1024;
......@@ -69,6 +69,7 @@ static void add_file_to_list(char *x, struct msgpath_array *arr) {/*{{{*/
}
arr->paths[arr->n].type = MTY_FILE;
arr->paths[arr->n].src.mpf.path = y;
arr->paths[arr->n].source_ft = ft;
++arr->n;
return;
}
......@@ -102,7 +103,7 @@ static void get_maildir_message_paths(char *folder, struct msgpath_array *arr)/*
strcpy(fname, subdir);
strcat(fname, "/");
strcat(fname, de->d_name);
add_file_to_list(fname, arr);
add_file_to_list(fname, arr, FT_MAILDIR);
}
closedir(d);
}
......@@ -149,7 +150,7 @@ static void get_mh_message_paths(char *folder, struct msgpath_array *arr)/*{{{*/
strcat(fname, "/");
strcat(fname, de->d_name);
if (valid_mh_filename_p(de->d_name)) {
add_file_to_list(fname, arr);
add_file_to_list(fname, arr, FT_MH);
}
}
closedir(d);
......
......@@ -42,6 +42,16 @@ enum message_type {/*{{{*/
};
/*}}}*/
enum folder_type {/*{{{*/
FT_MAILDIR,
FT_MH,
FT_MBOX,
FT_RAW,
FT_EXCERPT,
FT_IMAP
};
/*}}}*/
struct msgpath {/*{{{*/
enum message_type type; /* selector for union 'src' */
union {
......@@ -60,6 +70,10 @@ struct msgpath {/*{{{*/
time_t date; /* representation of Date: header in message */
int tid; /* thread-id */
/* Track the folder type this came from, so we know the difference
between MH and Maildir, both of which have type MTY_FILE. */
enum folder_type source_ft;
/* Message flags. */
unsigned int seen:1;
unsigned int replied:1;
......@@ -243,16 +257,6 @@ struct database {/*{{{*/
};
/*}}}*/
enum folder_type {/*{{{*/
FT_MAILDIR,
FT_MH,
FT_MBOX,
FT_RAW,
FT_EXCERPT,
FT_IMAP
};
/*}}}*/
struct string_list {/*{{{*/
struct string_list *next;
struct string_list *prev;
......
# Test that we do not get the following error:
#
# Cannot add '..../test/55-numeric-subfolder-name.data/messages/mh/99/2' to database; stat() failed
#
add_messages mh 99
From: root <root@localhost>
To: mairix-users@lists.sourceforge.net
Subject: I like to name my folders after numbers
Message-ID: <12345@and.my.message-ids.too>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Date: Mon, 17 Jul 2017 20:58:25 +0100
99
From: root <root@localhost>
To: mairix-users@lists.sourceforge.net
Subject: I like to name my folders after numbers
Message-ID: <12345@and.my.message-ids.too>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Date: Mon, 17 Jul 2017 20:58:25 +0100
99
......@@ -945,7 +945,14 @@ run_mairix() {
#
update_database () {
[[ $# -eq 0 ]] || error "update_database does not accept arguments, but received $# arguments."
run_mairix "$MARKER_NO_DUMP"
run_mairix "$MARKER_NO_DUMP" 2>"$DATA_DIR_ABS/update_database.stderr"
if [ -s "$DATA_DIR_ABS/update_database.stderr" ]; then
echo "mairix unexpectedly emited error output:"
echo "<<<<<"
cat "$DATA_DIR_ABS/update_database.stderr"
echo ">>>>>"
false
fi
}
#--------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment