Package: mairix
Version: 0.15.2-1
Severity: normal
Mairix is great -- fast and does just what I need.
Here is a small improvement, submitted because by doing something like
this:
mairix -o inbox f:aims d:2w-
I carelessly trashed my inbox, which had all my emails for the last 10
years. I was trying to get the search to return only msgs in the
inbox, and of course '-o' is not what I wanted! I had backups so no
worries, but meanwhile here is a patch so that mairix will refuse to
do what I mistakenly asked it to.
Here is the patch, which also patches the .texi documentation. I
didn't patch the man page since it doesn't describe the '-o' option.
I'm not sure the patch is 100% right. Probably it doesn't catch all
cases where the user might harm themselves; for example, what if the
the mfolder is specified as ../Mail/inbox, then mairix won't know that
the search output will trash inbox (assuming that Mail as the base
directory). But it's a start.
Anyway the patch:
--- mairix.c.old 2005-02-03 16:52:02.000000000 -0500
+++ mairix.c 2005-03-01 01:52:55.000000000 -0500
@@ -54,6 +54,38 @@
return 1;
}
/*}}}*/
+
+/* return 1 iff string S is a member of the colon-separated
+ folder-list LIST */
+
+static int member_of (char *s, char *list) {
+ char *padded_s, *padded_list;
+ int result;
+
+ if (!s || !list)
+ return 0;
+ /* make copy of s padded with : on front and back */
+ padded_s = Malloc(3+strlen(s));
+ strcpy (padded_s, ":");
+ strcat (padded_s, s);
+ strcat (padded_s, ":");
+
+ /* make copy of list similarly padded */
+ padded_list = Malloc(3+strlen(list));
+ strcpy (padded_list, ":");
+ strcat (padded_list, list);
+ strcat (padded_list, ":");
+
+ /* now search for the folder in the list of folders. Colon padding
+ means no funny boundary cases to worry about. Should use a
+ regexp instead (or python!). */
+ result = strstr (padded_list, padded_s);
+ free (padded_list);
+ free (padded_s);
+ return (result ? 1 : 0);
+}
+
+
static char *copy_value(char *text)/*{{{*/
{
char *p;
@@ -483,8 +515,13 @@
exit(2);
}
mfolder = new_string("");
+ } else if (maildir_folders && member_of (mfolder, maildir_folders) ||
+ mh_folders && member_of (mfolder, mh_folders) ||
+ mboxen && member_of (mfolder, mboxen)) {
+ fprintf (stderr, "You requested that search results go to the folder
'%s'.\nThat is also one of the indexed mail folders! For your own good, I
refuse to output search results to an indexed mail folder.\n", mfolder);
+ exit(3);
}
-
+
return search_top(do_threads, do_augment, database_path, folder_base,
mfolder, argv, output_folder_type, verbose);
} else {
--- mairix.texi.old 2005-02-03 16:52:02.000000000 -0500
+++ mairix.texi 2005-03-01 02:13:40.000000000 -0500
@@ -529,6 +529,13 @@
and @samp{.} characters as the @b{mfolder} line in the @file{.mairixrc} file
does.
[EMAIL PROTECTED] will refuse to output search results (whether specified
+by the @samp{-o} or in the @file{.mairixrc} file) into one of the
+folders that are indexed; it figures out that list by looking in the
[EMAIL PROTECTED] file, or in the file you specify using the @samp{-f}
+option. This sanity check prevents you inadvertantly destroying one
+of your important folders (but won't catch all such cases, sadly).
+
The search mode runs when there is at least one search expression. Search
expressions can take forms such as (in increasing order of complexity):
-- System Information:
Debian Release: 3.1
APT prefers testing
APT policy: (990, 'testing'), (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.27-200502251
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)
Versions of packages mairix depends on:
ii libc6 2.3.2.ds1-20 GNU C Library: Shared libraries an
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]