Add from: header to the outgoing message.
Showing
1 changed file
with
75 additions
and
31 deletions
... | @@ -21,6 +21,7 @@ | ... | @@ -21,6 +21,7 @@ |
21 | #include <sys/stat.h> | 21 | #include <sys/stat.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #include <stdarg.h> | 23 | #include <stdarg.h> |
24 | #include <pwd.h> | ||
24 | 25 | ||
25 | const char *argp_program_version = "send (" PACKAGE_STRING ")"; | 26 | const char *argp_program_version = "send (" PACKAGE_STRING ")"; |
26 | static char doc[] = N_("GNU MH send\v" | 27 | static char doc[] = N_("GNU MH send\v" |
... | @@ -28,29 +29,6 @@ static char doc[] = N_("GNU MH send\v" | ... | @@ -28,29 +29,6 @@ static char doc[] = N_("GNU MH send\v" |
28 | "Use -help to obtain the list of traditional MH options."); | 29 | "Use -help to obtain the list of traditional MH options."); |
29 | static char args_doc[] = N_("file [file...]"); | 30 | static char args_doc[] = N_("file [file...]"); |
30 | 31 | ||
31 | #define ARG_ALIAS 257 | ||
32 | #define ARG_DRAFT 258 | ||
33 | #define ARG_DRAFTFOLDER 259 | ||
34 | #define ARG_DRAFTMESSAGE 260 | ||
35 | #define ARG_NODRAFTFOLDER 261 | ||
36 | #define ARG_FILTER 262 | ||
37 | #define ARG_NOFILTER 263 | ||
38 | #define ARG_FORMAT 264 | ||
39 | #define ARG_NOFORMAT 265 | ||
40 | #define ARG_FORWARD 266 | ||
41 | #define ARG_NOFORWARD 267 | ||
42 | #define ARG_MIME 268 | ||
43 | #define ARG_NOMIME 269 | ||
44 | #define ARG_MSGID 270 | ||
45 | #define ARG_NOMSGID 271 | ||
46 | #define ARG_PUSH 272 | ||
47 | #define ARG_NOPUSH 273 | ||
48 | #define ARG_SPLIT 274 | ||
49 | #define ARG_VERBOSE 275 | ||
50 | #define ARG_NOVERBOSE 276 | ||
51 | #define ARG_WATCH 277 | ||
52 | #define ARG_NOWATCH 278 | ||
53 | #define ARG_WIDTH 279 | ||
54 | 32 | ||
55 | /* GNU options */ | 33 | /* GNU options */ |
56 | static struct argp_option options[] = { | 34 | static struct argp_option options[] = { |
... | @@ -59,11 +37,11 @@ static struct argp_option options[] = { | ... | @@ -59,11 +37,11 @@ static struct argp_option options[] = { |
59 | {"draft", ARG_DRAFT, NULL, 0, | 37 | {"draft", ARG_DRAFT, NULL, 0, |
60 | N_("Use prepared draft") }, | 38 | N_("Use prepared draft") }, |
61 | {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, | 39 | {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, |
62 | N_("* Specify the folder for message drafts") }, | 40 | N_("Specify the folder for message drafts") }, |
63 | {"draftmessage", ARG_DRAFTMESSAGE, N_("MESSAGE"), 0, | 41 | {"draftmessage", ARG_DRAFTMESSAGE, NULL, 0, |
64 | N_("* Invoke the draftmessage facility") }, | 42 | N_("Treat the arguments as a list of messages from the draftfolder") }, |
65 | {"nodraftfolder", ARG_NODRAFTFOLDER, NULL, 0, | 43 | {"nodraftfolder", ARG_NODRAFTFOLDER, NULL, 0, |
66 | N_("* Undo the effect of the last --draftfolder option") }, | 44 | N_("Undo the effect of the last --draftfolder option") }, |
67 | {"filter", ARG_FILTER, N_("FILE"), 0, | 45 | {"filter", ARG_FILTER, N_("FILE"), 0, |
68 | N_("* Set the filter program to preprocess the body of the message") }, | 46 | N_("* Set the filter program to preprocess the body of the message") }, |
69 | {"nofilter", ARG_NOFILTER, NULL, 0, | 47 | {"nofilter", ARG_NOFILTER, NULL, 0, |
... | @@ -78,7 +56,7 @@ static struct argp_option options[] = { | ... | @@ -78,7 +56,7 @@ static struct argp_option options[] = { |
78 | N_("* Use MIME encapsulation") }, | 56 | N_("* Use MIME encapsulation") }, |
79 | {"nomime", ARG_NOMIME, NULL, OPTION_HIDDEN, "" }, | 57 | {"nomime", ARG_NOMIME, NULL, OPTION_HIDDEN, "" }, |
80 | {"msgid", ARG_MSGID, N_("BOOL"), OPTION_ARG_OPTIONAL, | 58 | {"msgid", ARG_MSGID, N_("BOOL"), OPTION_ARG_OPTIONAL, |
81 | N_("* Add Message-ID: field") }, | 59 | N_("Add Message-ID: field") }, |
82 | {"nomsgid", ARG_NOMSGID, NULL, OPTION_HIDDEN, ""}, | 60 | {"nomsgid", ARG_NOMSGID, NULL, OPTION_HIDDEN, ""}, |
83 | {"push", ARG_PUSH, N_("BOOL"), OPTION_ARG_OPTIONAL, | 61 | {"push", ARG_PUSH, N_("BOOL"), OPTION_ARG_OPTIONAL, |
84 | N_("Run in the backround.") }, | 62 | N_("Run in the backround.") }, |
... | @@ -118,6 +96,7 @@ struct mh_option mh_option[] = { | ... | @@ -118,6 +96,7 @@ struct mh_option mh_option[] = { |
118 | }; | 96 | }; |
119 | 97 | ||
120 | static int use_draft; /* Use the prepared draft */ | 98 | static int use_draft; /* Use the prepared draft */ |
99 | static char *draft_folder; /* Use this draft folder */ | ||
121 | static int reformat_recipients; /* --format option */ | 100 | static int reformat_recipients; /* --format option */ |
122 | static int forward_notice; /* Forward the failure notice to the sender, | 101 | static int forward_notice; /* Forward the failure notice to the sender, |
123 | --forward flag */ | 102 | --forward flag */ |
... | @@ -153,8 +132,19 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -153,8 +132,19 @@ opt_handler (int key, char *arg, void *unused) |
153 | break; | 132 | break; |
154 | 133 | ||
155 | case ARG_DRAFTFOLDER: | 134 | case ARG_DRAFTFOLDER: |
156 | case ARG_DRAFTMESSAGE: | 135 | draft_folder = arg; |
136 | break; | ||
137 | |||
157 | case ARG_NODRAFTFOLDER: | 138 | case ARG_NODRAFTFOLDER: |
139 | draft_folder = NULL; | ||
140 | break; | ||
141 | |||
142 | case ARG_DRAFTMESSAGE: | ||
143 | if (!draft_folder) | ||
144 | draft_folder = mh_global_profile_get ("Draft-Folder", | ||
145 | mu_path_folder_dir); | ||
146 | break; | ||
147 | |||
158 | case ARG_FILTER: | 148 | case ARG_FILTER: |
159 | case ARG_NOFILTER: | 149 | case ARG_NOFILTER: |
160 | return 1; | 150 | return 1; |
... | @@ -267,7 +257,7 @@ check_file (char *name) | ... | @@ -267,7 +257,7 @@ check_file (char *name) |
267 | { | 257 | { |
268 | mailbox_t mbox; | 258 | mailbox_t mbox; |
269 | 259 | ||
270 | mbox = mh_open_msg_file (name); | 260 | mbox = mh_open_msg_file (draft_folder, name); |
271 | if (!mbox) | 261 | if (!mbox) |
272 | return 1; | 262 | return 1; |
273 | if (!mbox_list && list_create (&mbox_list)) | 263 | if (!mbox_list && list_create (&mbox_list)) |
... | @@ -332,6 +322,24 @@ open_mailer () | ... | @@ -332,6 +322,24 @@ open_mailer () |
332 | return mailer; | 322 | return mailer; |
333 | } | 323 | } |
334 | 324 | ||
325 | static void | ||
326 | create_message_id (header_t hdr) | ||
327 | { | ||
328 | char date[4+2+2+2+2+2+1]; | ||
329 | time_t t = time (NULL); | ||
330 | struct tm *tm = localtime (&t); | ||
331 | char *host; | ||
332 | char *p; | ||
333 | |||
334 | strftime (date, sizeof date, "%Y%m%d%H%M%S", tm); | ||
335 | mu_get_host_name (&host); | ||
336 | |||
337 | asprintf (&p, "<%s.%lu@%s>", date, (unsigned long) getpid (), host); | ||
338 | free (host); | ||
339 | header_set_value (hdr, MU_HEADER_MESSAGE_ID, p, 1); | ||
340 | free (p); | ||
341 | } | ||
342 | |||
335 | int | 343 | int |
336 | _action_send (void *item, void *data) | 344 | _action_send (void *item, void *data) |
337 | { | 345 | { |
... | @@ -339,6 +347,8 @@ _action_send (void *item, void *data) | ... | @@ -339,6 +347,8 @@ _action_send (void *item, void *data) |
339 | message_t msg; | 347 | message_t msg; |
340 | int rc; | 348 | int rc; |
341 | mailer_t mailer; | 349 | mailer_t mailer; |
350 | header_t hdr; | ||
351 | size_t n; | ||
342 | 352 | ||
343 | WATCH(("Getting message")); | 353 | WATCH(("Getting message")); |
344 | if ((rc = mailbox_get_message (mbox, 1, &msg))) | 354 | if ((rc = mailbox_get_message (mbox, 1, &msg))) |
... | @@ -347,6 +357,40 @@ _action_send (void *item, void *data) | ... | @@ -347,6 +357,40 @@ _action_send (void *item, void *data) |
347 | return 1; | 357 | return 1; |
348 | } | 358 | } |
349 | 359 | ||
360 | if (message_get_header (msg, &hdr) == 0) | ||
361 | { | ||
362 | char date[80]; | ||
363 | time_t t = time (NULL); | ||
364 | struct tm *tm = localtime (&t); | ||
365 | |||
366 | strftime (date, sizeof date, "%a, %d %b %Y %H:%M:%S %Z", tm); | ||
367 | header_set_value (hdr, MU_HEADER_DATE, date, 1); | ||
368 | |||
369 | if (header_get_value (hdr, MU_HEADER_FROM, NULL, 0, &n)) | ||
370 | { | ||
371 | char *from; | ||
372 | char *email = mu_get_user_email (NULL); | ||
373 | struct passwd *pw = getpwuid (getuid ()); | ||
374 | if (pw && pw->pw_gecos[0]) | ||
375 | { | ||
376 | char *p = strchr (pw->pw_gecos, ','); | ||
377 | if (p) | ||
378 | *p = 0; | ||
379 | asprintf (&from, "\"%s\" <%s>", pw->pw_gecos, email); | ||
380 | free (email); | ||
381 | } | ||
382 | else | ||
383 | from = email; | ||
384 | |||
385 | header_set_value (hdr, MU_HEADER_FROM, from, 1); | ||
386 | free (from); | ||
387 | } | ||
388 | |||
389 | if (append_msgid | ||
390 | && header_get_value (hdr, MU_HEADER_MESSAGE_ID, NULL, 0, &n)) | ||
391 | create_message_id (hdr); | ||
392 | } | ||
393 | |||
350 | mailer = open_mailer (); | 394 | mailer = open_mailer (); |
351 | if (!mailer) | 395 | if (!mailer) |
352 | return 1; | 396 | return 1; |
... | @@ -366,7 +410,7 @@ _action_send (void *item, void *data) | ... | @@ -366,7 +410,7 @@ _action_send (void *item, void *data) |
366 | return 0; | 410 | return 0; |
367 | } | 411 | } |
368 | 412 | ||
369 | int | 413 | static int |
370 | send (int argc, char **argv) | 414 | send (int argc, char **argv) |
371 | { | 415 | { |
372 | int i, rc; | 416 | int i, rc; | ... | ... |
-
Please register or sign in to post a comment