aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-12-14 00:25:08 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-12-14 00:25:08 +0200
commit2854bd99ae3da9d88c41efa57628787514caec6f (patch)
tree421c4feb2b91d87a5c29e12ee699b71be82ac6c2
parent9eb7c789f39696c0ad80d4cafde5577d174c1985 (diff)
downloadmbar-2854bd99ae3da9d88c41efa57628787514caec6f.tar.gz
mbar-2854bd99ae3da9d88c41efa57628787514caec6f.tar.bz2
Implement the --keep option
-rw-r--r--mbar.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/mbar.c b/mbar.c
index cdd2432..1962c74 100644
--- a/mbar.c
+++ b/mbar.c
@@ -27,7 +27,7 @@ char *require_string;
char *template_file;
char *before_date;
char *mailbox_type;
-int stat_option;
+int keep_option;
#define EX_OK 0
@@ -83,7 +83,7 @@ build_requires (void)
char *prog_template = "require [\"fileinto\"${requires}];\n\
if ${cond} {\n\
- fileinto \"${dest}\";\n\
+ fileinto \"${dest}\";${keep:+keep;}\n\
}\n";
void
@@ -226,7 +226,7 @@ static mu_sieve_machine_t
build_sieve (char const *folder, int flags)
{
struct mu_wordsplit ws;
- char const *env[7];
+ char const *env[9];
char *dest;
int rc;
mu_sieve_machine_t mach;
@@ -237,7 +237,7 @@ build_sieve (char const *folder, int flags)
p++;
dest = mu_make_file_name (destdir, p);
- if (flags & FLG_MKDIR)
+ if (!(sieve_debug & MU_SIEVE_DRY_RUN) && (flags & FLG_MKDIR))
{
if (make_subdirs (dest))
exit (EX_UNAVAILABLE);
@@ -251,8 +251,11 @@ build_sieve (char const *folder, int flags)
env[4] = "requires";
env[5] = require_string ? require_string : "";
+
+ env[6] = "keep";
+ env[7] = keep_option ? "1" : "";
- env[6] = NULL;
+ env[8] = NULL;
ws.ws_env = env;
rc = mu_wordsplit (prog_template, &ws,
@@ -308,6 +311,9 @@ enumfun (mu_folder_t folder, struct mu_list_response *resp, void *data)
mu_sieve_machine_t mach;
mu_mailbox_t mbox;
int rc;
+ mu_url_t url;
+ char const *path;
+ struct stat st;
if (!(resp->type & MU_FOLDER_ATTRIBUTE_FILE))
return 0;
@@ -333,13 +339,27 @@ enumfun (mu_folder_t folder, struct mu_list_response *resp, void *data)
rc = mu_mailbox_open (mbox, MU_STREAM_RDWR);
if (rc)
abend ("mu_mailbox_open", resp->name, rc);
+
+ mu_mailbox_get_url (mbox, &url);
+ if (geteuid () == 0)
+ {
+ mu_url_sget_path (url, &path);
+ if (stat (path, &st))
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "stat", path, errno);
+ return 0;
+ }
+ if (setregid (st.st_gid, 0))
+ mu_error (_("%s: failed to switch to gid %lu: %s"),
+ path, (unsigned long)st.st_gid, mu_strerror (errno));
+ if (setreuid (st.st_uid, 0))
+ mu_error (_("%s: failed to switch to gid %lu"),
+ path, (unsigned long)st.st_gid, mu_strerror (errno));
+ }
if (!mailbox_type)
{
- mu_url_t url;
char const *scheme;
-
- mu_mailbox_get_url (mbox, &url);
mu_url_sget_scheme (url, &scheme);
rc = mu_registrar_set_default_scheme (scheme);
if (rc)
@@ -493,6 +513,9 @@ struct mu_option mbar_options[] = {
{ "locus", 0, NULL, MU_OPTION_DEFAULT,
N_("show action locations with verbose output"),
mu_c_bool, &locus_option },
+ { "keep", 'k', NULL, MU_OPTION_DEFAULT,
+ N_("don't remove messages after archiving"),
+ mu_c_bool, &keep_option },
{ NULL }
}, *options[] = { mbar_options, NULL };

Return to:

Send suggestions and report system problems to the System administrator.