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