Blame SOURCES/0206-mailx-introduce-debug-parameter-D.patch

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