Split off mail_send0(). It is used by mail_send() and mail_reply().
Showing
1 changed file
with
35 additions
and
18 deletions
... | @@ -32,6 +32,40 @@ int | ... | @@ -32,6 +32,40 @@ int |
32 | mail_send (int argc, char **argv) | 32 | mail_send (int argc, char **argv) |
33 | { | 33 | { |
34 | char *to = NULL, *cc = NULL, *bcc = NULL, *subj = NULL; | 34 | char *to = NULL, *cc = NULL, *bcc = NULL, *subj = NULL; |
35 | |||
36 | if (argc < 2) | ||
37 | to = readline ("To: "); | ||
38 | else | ||
39 | { | ||
40 | while (--argc) | ||
41 | { | ||
42 | char *p = alias_expand (*++argv); | ||
43 | if (to) | ||
44 | util_strcat(&to, ","); | ||
45 | util_strcat(&to, p); | ||
46 | free (p); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | if ((util_find_env ("askcc"))->set) | ||
51 | cc = readline ("Cc: "); | ||
52 | if ((util_find_env ("askbcc"))->set) | ||
53 | bcc = readline ("Bcc: "); | ||
54 | |||
55 | if ((util_find_env ("asksub"))->set) | ||
56 | subj = readline ("Subject: "); | ||
57 | else | ||
58 | subj = (util_find_env ("subject"))->value; | ||
59 | |||
60 | return mail_send0 (to, cc, bcc, subj); | ||
61 | } | ||
62 | |||
63 | /* Shared between mail_send() and mail_reply(); | ||
64 | NOTE: arguments should be allocated dynamically. They will be freed | ||
65 | before exit */ | ||
66 | int | ||
67 | mail_send0 (char *to, char *cc, char *bcc, char *subj) | ||
68 | { | ||
35 | char *buf = NULL; | 69 | char *buf = NULL; |
36 | size_t n = 0; | 70 | size_t n = 0; |
37 | int done = 0; | 71 | int done = 0; |
... | @@ -40,7 +74,7 @@ mail_send (int argc, char **argv) | ... | @@ -40,7 +74,7 @@ mail_send (int argc, char **argv) |
40 | FILE *file; | 74 | FILE *file; |
41 | const char *tmpdir; | 75 | const char *tmpdir; |
42 | 76 | ||
43 | /* We have to be extra carefull about opening temporary files, since we | 77 | /* We have to be extra careful about opening temporary files, since we |
44 | may be running with extra privilege i.e setgid(). */ | 78 | may be running with extra privilege i.e setgid(). */ |
45 | tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : "/tmp"; | 79 | tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : "/tmp"; |
46 | filename = alloca (strlen (tmpdir) + /*'/'*/1 + /* "muXXXXXX" */8 + 1); | 80 | filename = alloca (strlen (tmpdir) + /*'/'*/1 + /* "muXXXXXX" */8 + 1); |
... | @@ -62,23 +96,6 @@ mail_send (int argc, char **argv) | ... | @@ -62,23 +96,6 @@ mail_send (int argc, char **argv) |
62 | 96 | ||
63 | file = fdopen (fd, "w"); | 97 | file = fdopen (fd, "w"); |
64 | 98 | ||
65 | if (argc < 2) | ||
66 | to = readline ("To: "); | ||
67 | else | ||
68 | { | ||
69 | /* figure it out from argv */ | ||
70 | } | ||
71 | |||
72 | if ((util_find_env ("askcc"))->set) | ||
73 | cc = readline ("Cc: "); | ||
74 | if ((util_find_env ("askbcc"))->set) | ||
75 | bcc = readline ("Bcc: "); | ||
76 | |||
77 | if ((util_find_env ("asksub"))->set) | ||
78 | subj = readline ("Subject: "); | ||
79 | else | ||
80 | subj = (util_find_env ("subject"))->value; | ||
81 | |||
82 | while (getline (&buf, &n, stdin) >= 0 && !done) | 99 | while (getline (&buf, &n, stdin) >= 0 && !done) |
83 | { | 100 | { |
84 | if (buf[0] == (util_find_env("escape"))->value[0]) | 101 | if (buf[0] == (util_find_env("escape"))->value[0]) | ... | ... |
-
Please register or sign in to post a comment