A framework for send utility.
Showing
1 changed file
with
240 additions
and
0 deletions
mh/send.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2003 Free Software Foundation, Inc. | ||
3 | |||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Mailutils is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Mailutils; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | /* MH send command */ | ||
19 | |||
20 | #include <mh.h> | ||
21 | |||
22 | const char *argp_program_version = "send (" PACKAGE_STRING ")"; | ||
23 | static char doc[] = N_("GNU MH send\v" | ||
24 | "Options marked with `*' are not yet implemented.\n" | ||
25 | "Use -help to obtain the list of traditional MH options."); | ||
26 | static char args_doc[] = N_("file [file...]"); | ||
27 | |||
28 | #define ARG_ALIAS 257 | ||
29 | #define ARG_DRAFT 258 | ||
30 | #define ARG_DRAFTFOLDER 259 | ||
31 | #define ARG_DRAFTMESSAGE 260 | ||
32 | #define ARG_NODRAFTFOLDER 261 | ||
33 | #define ARG_FILTER 262 | ||
34 | #define ARG_NOFILTER 263 | ||
35 | #define ARG_FORMAT 264 | ||
36 | #define ARG_NOFORMAT 265 | ||
37 | #define ARG_FORWARD 266 | ||
38 | #define ARG_NOFORWARD 267 | ||
39 | #define ARG_MIME 268 | ||
40 | #define ARG_NOMIME 269 | ||
41 | #define ARG_MSGID 270 | ||
42 | #define ARG_NOMSGID 271 | ||
43 | #define ARG_PUSH 272 | ||
44 | #define ARG_NOPUSH 273 | ||
45 | #define ARG_SPLIT 274 | ||
46 | #define ARG_VERBOSE 275 | ||
47 | #define ARG_NOVERBOSE 276 | ||
48 | #define ARG_WATCH 277 | ||
49 | #define ARG_NOWATCH 278 | ||
50 | #define ARG_WIDTH 279 | ||
51 | |||
52 | /* GNU options */ | ||
53 | static struct argp_option options[] = { | ||
54 | {"alias", ARG_ALIAS, N_("FILE"), 0, | ||
55 | N_("* Specify additional alias file") }, | ||
56 | {"draft", ARG_DRAFT, NULL, 0, | ||
57 | N_("* Use prepared draft") }, | ||
58 | {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, | ||
59 | N_("* Specify the folder for message drafts") }, | ||
60 | {"draftmessage", ARG_DRAFTMESSAGE, N_("MESSAGE"), 0, | ||
61 | N_("* Invoke the draftmessage facility") }, | ||
62 | {"nodraftfolder", ARG_NODRAFTFOLDER, NULL, 0, | ||
63 | N_("* Undo the effect of the last --draftfolder option") }, | ||
64 | {"filter", ARG_FILTER, N_("FILE"), 0, | ||
65 | N_("* Set the filter program to preprocess the body of the message") }, | ||
66 | {"nofilter", ARG_NOFILTER, NULL, 0, | ||
67 | N_("* Undo the effect of the last --filter option") }, | ||
68 | {"format", ARG_FORMAT, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
69 | N_("* Reformat To: and Cc: addresses") }, | ||
70 | {"noformat", ARG_NOFORMAT, NULL, OPTION_HIDDEN, "" }, | ||
71 | {"forward", ARG_FORWARD, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
72 | N_("* In case of failure forward the draft along with the failure notice to the sender.") }, | ||
73 | {"noforward", ARG_NOFORWARD, NULL, OPTION_HIDDEN, "" }, | ||
74 | {"mime", ARG_MIME, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
75 | N_("* Use MIME encapsulation") }, | ||
76 | {"nomime", ARG_NOMIME, NULL, OPTION_HIDDEN, "" }, | ||
77 | {"msgid", ARG_MSGID, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
78 | N_("* Add Message-ID: field") }, | ||
79 | {"nomsgid", ARG_NOMSGID, NULL, OPTION_HIDDEN, ""}, | ||
80 | {"push", ARG_PUSH, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
81 | N_("* Run in the backround.") }, | ||
82 | {"nopush", ARG_NOPUSH, NULL, OPTION_HIDDEN, "" }, | ||
83 | {"split", ARG_SPLIT, N_("SECONDS"), 0, | ||
84 | N_("* Split the draft into several partial messages and send them with SECONDS interval") }, | ||
85 | {"verbose", ARG_VERBOSE, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
86 | N_("* Print the transcript of interactions with the transport system") }, | ||
87 | {"noverbose", ARG_NOVERBOSE, NULL, OPTION_HIDDEN, "" }, | ||
88 | {"watch", ARG_WATCH, N_("BOOL"), OPTION_ARG_OPTIONAL, | ||
89 | N_("* Monitor the delivery of mail") }, | ||
90 | {"nowatch", ARG_NOWATCH, NULL, OPTION_HIDDEN, "" }, | ||
91 | {"width", ARG_WIDTH, N_("NUMBER"), 0, | ||
92 | N_("* Make header fields no longer than NUMBER columns") }, | ||
93 | { 0 } | ||
94 | }; | ||
95 | |||
96 | /* Traditional MH options */ | ||
97 | struct mh_option mh_option[] = { | ||
98 | {"alias", 1, 0, "aliasfile" }, | ||
99 | {"draft", 5, 0, NULL }, | ||
100 | {"draftfolder", 6, 0, "folder" }, | ||
101 | {"draftmessage", 6, 0, "message"}, | ||
102 | {"nodraftfolder", 3, 0, NULL }, | ||
103 | {"filter", 2, 0, "filterfile"}, | ||
104 | {"nofilter", 3, 0, NULL }, | ||
105 | {"format", 4, MH_OPT_BOOL, NULL}, | ||
106 | {"forward", 4, MH_OPT_BOOL, NULL}, | ||
107 | {"mime", 2, MH_OPT_BOOL, NULL}, | ||
108 | {"msgid", 2, MH_OPT_BOOL, NULL}, | ||
109 | {"push", 1, MH_OPT_BOOL, NULL}, | ||
110 | {"split", 1, 0, "seconds"}, | ||
111 | {"verbose", 1, MH_OPT_BOOL, NULL}, | ||
112 | {"watch", 2, MH_OPT_BOOL, NULL}, | ||
113 | {"width", 2, 0, NULL }, | ||
114 | { 0 } | ||
115 | }; | ||
116 | |||
117 | static int reformat_recipients; /* --format option */ | ||
118 | static int forward_notice; /* Forward the failure notice to the sender, | ||
119 | --forward flag */ | ||
120 | static int mime_encaps; /* Use MIME encapsulation */ | ||
121 | static int append_msgid; /* Append Message-ID: header */ | ||
122 | static int background; /* Operate in the background */ | ||
123 | |||
124 | static int split_message; /* Split the message */ | ||
125 | static unsigned long split_interval; /* Interval in seconds between sending two | ||
126 | successive partial messages */ | ||
127 | |||
128 | static int verbose; /* Produce verbose diagnostics */ | ||
129 | static int watch; /* Watch the delivery process */ | ||
130 | static unsigned width = 76; /* Maximum width of header fields */ | ||
131 | |||
132 | static int | ||
133 | opt_handler (int key, char *arg, void *unused) | ||
134 | { | ||
135 | char *p; | ||
136 | |||
137 | switch (key) | ||
138 | { | ||
139 | case ARG_ALIAS: | ||
140 | case ARG_DRAFT: | ||
141 | case ARG_DRAFTFOLDER: | ||
142 | case ARG_DRAFTMESSAGE: | ||
143 | case ARG_NODRAFTFOLDER: | ||
144 | case ARG_FILTER: | ||
145 | case ARG_NOFILTER: | ||
146 | return 1; | ||
147 | |||
148 | case ARG_FORMAT: | ||
149 | reformat_recipients = is_true(arg); | ||
150 | break; | ||
151 | |||
152 | case ARG_NOFORMAT: | ||
153 | reformat_recipients = 0; | ||
154 | break; | ||
155 | |||
156 | case ARG_FORWARD: | ||
157 | forward_notice = is_true(arg); | ||
158 | break; | ||
159 | |||
160 | case ARG_NOFORWARD: | ||
161 | forward_notice = 0; | ||
162 | break; | ||
163 | |||
164 | case ARG_MIME: | ||
165 | mime_encaps = is_true(arg); | ||
166 | break; | ||
167 | |||
168 | case ARG_NOMIME: | ||
169 | mime_encaps = 0; | ||
170 | break; | ||
171 | |||
172 | case ARG_MSGID: | ||
173 | append_msgid = is_true(arg); | ||
174 | break; | ||
175 | |||
176 | case ARG_NOMSGID: | ||
177 | append_msgid = 0; | ||
178 | break; | ||
179 | |||
180 | case ARG_PUSH: | ||
181 | background = is_true(arg); | ||
182 | break; | ||
183 | |||
184 | case ARG_NOPUSH: | ||
185 | background = 0; | ||
186 | break; | ||
187 | |||
188 | case ARG_SPLIT: | ||
189 | split_message = 1; | ||
190 | split_interval = strtoul(arg, &p, 10); | ||
191 | if (*p) | ||
192 | { | ||
193 | mh_error (_("Invalid number")); | ||
194 | exit (1); | ||
195 | } | ||
196 | break; | ||
197 | |||
198 | case ARG_VERBOSE: | ||
199 | verbose = is_true(arg); | ||
200 | break; | ||
201 | |||
202 | case ARG_NOVERBOSE: | ||
203 | verbose = 0; | ||
204 | break; | ||
205 | |||
206 | case ARG_WATCH: | ||
207 | watch = is_true(arg); | ||
208 | break; | ||
209 | |||
210 | case ARG_NOWATCH: | ||
211 | watch = 0; | ||
212 | break; | ||
213 | |||
214 | case ARG_WIDTH: | ||
215 | width = strtoul(arg, &p, 10); | ||
216 | if (*p) | ||
217 | { | ||
218 | mh_error (_("Invalid number")); | ||
219 | exit (1); | ||
220 | } | ||
221 | break; | ||
222 | |||
223 | default: | ||
224 | return 1; | ||
225 | } | ||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | int | ||
230 | main (int argc, char **argv) | ||
231 | { | ||
232 | int index; | ||
233 | |||
234 | mu_init_nls (); | ||
235 | |||
236 | mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, | ||
237 | opt_handler, NULL, &index); | ||
238 | |||
239 | return 0; | ||
240 | } |
-
Please register or sign in to post a comment