From 5ae2faba4071002bf012d14a2d6e132b5d472e03 Mon Sep 17 00:00:00 2001 From: Matej Habrnal Date: Thu, 7 Apr 2016 15:55:04 +0200 Subject: [PATCH] mailx: introduce debug parameter -D Related to rhbz#1281312 Signed-off-by: Matej Habrnal Conflicts: src/plugins/reporter-mailx.c --- src/plugins/reporter-mailx.c | 60 +++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/plugins/reporter-mailx.c b/src/plugins/reporter-mailx.c index c531541..feeb900 100644 --- a/src/plugins/reporter-mailx.c +++ b/src/plugins/reporter-mailx.c @@ -38,6 +38,11 @@ #define PR_ATTACH_BINARY "\n%attach:: %binary" +enum { + RM_FLAG_NOTIFY = (1 << 0), + RM_FLAG_DEBUG = (1 << 1) +}; + static void exec_and_feed_input(const char* text, char **args) { int pipein[2]; @@ -99,7 +104,7 @@ static void create_and_send_email( const char *dump_dir_name, map_string_t *settings, const char *fmt_file, - bool notify_only) + int flag) { problem_data_t *problem_data = create_problem_data_for_reporting(dump_dir_name); if (!problem_data) @@ -113,10 +118,6 @@ static void create_and_send_email( env = getenv("Mailx_SendBinaryData"); bool send_binary_data = string_to_bool(env ? env : get_map_string_item_or_empty(settings, "SendBinaryData")); - char **args = NULL; - unsigned arg_size = 0; - args = append_str_to_vector(args, &arg_size, "/bin/mailx"); - problem_formatter_t *pf = problem_formatter_new(); /* formatting file is not set */ if (fmt_file == NULL) @@ -148,17 +149,33 @@ static void create_and_send_email( const char *subject = problem_report_get_summary(pr); const char *dsc = problem_report_get_description(pr); - log_debug("subject: %s\n" - "\n" - "%s" - "\n" - , subject - , dsc); + if (flag & RM_FLAG_DEBUG) + { + printf("subject: %s\n" + "\n" + "%s" + "\n" + , subject + , dsc); + + puts("attachments:"); + for (GList *a = problem_report_get_attachments(pr); a != NULL; a = g_list_next(a)) + printf(" %s\n", (const char *)a->data); + + problem_report_free(pr); + problem_formatter_free(pf); + free(email_from); + free(email_to); + exit(0); + } + + char **args = NULL; + unsigned arg_size = 0; + args = append_str_to_vector(args, &arg_size, "/bin/mailx"); /* attaching files to the email */ for (GList *a = problem_report_get_attachments(pr); a != NULL; a = g_list_next(a)) { - log_debug("Attaching '%s' to the email", (const char *)a->data); args = append_str_to_vector(args, &arg_size, "-a"); char *full_name = concat_path_file(realpath(dump_dir_name, NULL), a->data); args = append_str_to_vector(args, &arg_size, full_name); @@ -181,6 +198,12 @@ static void create_and_send_email( putenv((char*)"sendwait=1"); log(_("Sending an email...")); + + if (flag & RM_FLAG_NOTIFY) + log(_("Sending a notification email to: %s"), email_to); + else + log(_("Sending an email...")); + exec_and_feed_input(dsc, args); problem_report_free(pr); @@ -193,7 +216,7 @@ static void create_and_send_email( problem_data_free(problem_data); - if (!notify_only) + if (!(flag & RM_FLAG_NOTIFY)) { struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (dd) @@ -243,6 +266,7 @@ int main(int argc, char **argv) OPT_c = 1 << 2, OPT_F = 1 << 3, OPT_n = 1 << 4, + OPT_D = 1 << 5, }; /* Keep enum above and order of options below in sync! */ struct options program_options[] = { @@ -251,6 +275,7 @@ int main(int argc, char **argv) OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")), OPT_STRING('F', NULL, &fmt_file , "FILE" , _("Formatting file for an email")), OPT_BOOL('n', "notify-only", NULL , _("Notify only (Do not mark the report as sent)")), + OPT_BOOL( 'D', NULL, NULL , _("Debug")), OPT_END() }; unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); @@ -260,7 +285,14 @@ int main(int argc, char **argv) map_string_t *settings = new_map_string(); load_conf_file(conf_file, settings, /*skip key w/o values:*/ false); - create_and_send_email(dump_dir_name, settings, fmt_file, /*notify_only*/(opts & OPT_n)); + int flag = 0; + if (opts & OPT_n) + flag |= RM_FLAG_NOTIFY; + + if (opts & OPT_D) + flag |= RM_FLAG_DEBUG; + + create_and_send_email(dump_dir_name, settings, fmt_file, flag); free_map_string(settings); return 0; -- 1.8.3.1