Almost finished.
Showing
1 changed file
with
50 additions
and
14 deletions
... | @@ -76,6 +76,7 @@ struct mh_option mh_option[] = { | ... | @@ -76,6 +76,7 @@ struct mh_option mh_option[] = { |
76 | {"width", 1, 'w', MH_OPT_ARG, "number"}, | 76 | {"width", 1, 'w', MH_OPT_ARG, "number"}, |
77 | {"draftfolder", 6, 'd', MH_OPT_ARG, "folder"}, | 77 | {"draftfolder", 6, 'd', MH_OPT_ARG, "folder"}, |
78 | {"nodraftfolder", 3, ARG_NODRAFTFOLDER, }, | 78 | {"nodraftfolder", 3, ARG_NODRAFTFOLDER, }, |
79 | {"draftmessage", 6, 'm' }, | ||
79 | {"editor", 1, 'e', MH_OPT_ARG, "program"}, | 80 | {"editor", 1, 'e', MH_OPT_ARG, "program"}, |
80 | {"noedit", 3, ARG_NOEDIT, }, | 81 | {"noedit", 3, ARG_NOEDIT, }, |
81 | {"fcc", 1, ARG_FCC, MH_OPT_ARG, "folder"}, | 82 | {"fcc", 1, ARG_FCC, MH_OPT_ARG, "folder"}, |
... | @@ -101,8 +102,9 @@ static char *format_str = | ... | @@ -101,8 +102,9 @@ static char *format_str = |
101 | 102 | ||
102 | static mh_format_t format; | 103 | static mh_format_t format; |
103 | static int width = 80; | 104 | static int width = 80; |
104 | static char *draft_folder; | 105 | |
105 | static char *draft_file; | 106 | struct mh_whatnow_env wh_env = { 0 }; |
107 | static int initial_edit = 1; | ||
106 | static mh_msgset_t msgset; | 108 | static mh_msgset_t msgset; |
107 | static mailbox_t mbox; | 109 | static mailbox_t mbox; |
108 | static int build_only = 0; /* --build flag */ | 110 | static int build_only = 0; /* --build flag */ |
... | @@ -117,6 +119,7 @@ decode_cc_flag (const char *opt, const char *arg) | ... | @@ -117,6 +119,7 @@ decode_cc_flag (const char *opt, const char *arg) |
117 | mh_error (_("%s %s is unknown"), opt, arg); | 119 | mh_error (_("%s %s is unknown"), opt, arg); |
118 | exit (1); | 120 | exit (1); |
119 | } | 121 | } |
122 | return 0; /* never reached */ | ||
120 | } | 123 | } |
121 | 124 | ||
122 | static int | 125 | static int |
... | @@ -125,6 +128,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -125,6 +128,7 @@ opt_handler (int key, char *arg, void *unused) |
125 | switch (key) | 128 | switch (key) |
126 | { | 129 | { |
127 | case 'b': | 130 | case 'b': |
131 | case ARG_NOWHATNOWPROC: | ||
128 | build_only = 1; | 132 | build_only = 1; |
129 | break; | 133 | break; |
130 | 134 | ||
... | @@ -137,7 +141,11 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -137,7 +141,11 @@ opt_handler (int key, char *arg, void *unused) |
137 | break; | 141 | break; |
138 | 142 | ||
139 | case 'd': | 143 | case 'd': |
140 | draft_folder = arg; | 144 | wh_env.draftfolder = arg; |
145 | break; | ||
146 | |||
147 | case 'e': | ||
148 | wh_env.editor = arg; | ||
141 | break; | 149 | break; |
142 | 150 | ||
143 | case '+': | 151 | case '+': |
... | @@ -149,6 +157,10 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -149,6 +157,10 @@ opt_handler (int key, char *arg, void *unused) |
149 | mh_read_formfile (arg, &format_str); | 157 | mh_read_formfile (arg, &format_str); |
150 | break; | 158 | break; |
151 | 159 | ||
160 | case 'm': | ||
161 | wh_env.draftmessage = arg; | ||
162 | break; | ||
163 | |||
152 | case 'w': | 164 | case 'w': |
153 | width = strtoul (arg, NULL, 0); | 165 | width = strtoul (arg, NULL, 0); |
154 | if (!width) | 166 | if (!width) |
... | @@ -159,17 +171,18 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -159,17 +171,18 @@ opt_handler (int key, char *arg, void *unused) |
159 | break; | 171 | break; |
160 | 172 | ||
161 | case ARG_NODRAFTFOLDER: | 173 | case ARG_NODRAFTFOLDER: |
162 | draft_folder = NULL; | 174 | wh_env.draftfolder = NULL; |
163 | break; | 175 | break; |
164 | 176 | ||
177 | case ARG_NOEDIT: | ||
178 | initial_edit = 0; | ||
179 | break; | ||
180 | |||
165 | case ARG_QUERY: | 181 | case ARG_QUERY: |
166 | query_mode = is_true (arg); | 182 | query_mode = is_true (arg); |
167 | break; | 183 | break; |
168 | 184 | ||
169 | case 'a': | 185 | case 'a': |
170 | case 'm': | ||
171 | case 'e': | ||
172 | case ARG_NOEDIT: | ||
173 | case ARG_FCC: | 186 | case ARG_FCC: |
174 | case ARG_FILTER: | 187 | case ARG_FILTER: |
175 | case ARG_INPLACE: | 188 | case ARG_INPLACE: |
... | @@ -193,11 +206,11 @@ make_draft () | ... | @@ -193,11 +206,11 @@ make_draft () |
193 | #define bufsize sizeof(buffer) | 206 | #define bufsize sizeof(buffer) |
194 | 207 | ||
195 | /* FIXME: first check if the draft exists */ | 208 | /* FIXME: first check if the draft exists */ |
196 | fp = fopen (draft_file, "w+"); | 209 | fp = fopen (wh_env.file, "w+"); |
197 | if (!fp) | 210 | if (!fp) |
198 | { | 211 | { |
199 | mh_error (_("cannot open draft file %s: %s"), | 212 | mh_error (_("cannot open draft file %s: %s"), |
200 | draft_file, strerror (errno)); | 213 | wh_env.file, strerror (errno)); |
201 | exit (1); | 214 | exit (1); |
202 | } | 215 | } |
203 | 216 | ||
... | @@ -213,6 +226,24 @@ make_draft () | ... | @@ -213,6 +226,24 @@ make_draft () |
213 | mh_format (&format, msg, msgset.list[0], buffer, bufsize); | 226 | mh_format (&format, msg, msgset.list[0], buffer, bufsize); |
214 | fprintf (fp, "%s", buffer); | 227 | fprintf (fp, "%s", buffer); |
215 | fclose (fp); | 228 | fclose (fp); |
229 | |||
230 | { | ||
231 | url_t url; | ||
232 | size_t num; | ||
233 | char *msgname, *p; | ||
234 | |||
235 | mailbox_get_url (mbox, &url); | ||
236 | mh_message_number (msg, &num); | ||
237 | asprintf (&msgname, "%s/%lu", url_to_string (url), (unsigned long) num); | ||
238 | p = strchr (msgname, ':'); | ||
239 | if (!p) | ||
240 | wh_env.msg = msgname; | ||
241 | else | ||
242 | { | ||
243 | wh_env.msg = strdup (p+1); | ||
244 | free (msgname); | ||
245 | } | ||
246 | } | ||
216 | } | 247 | } |
217 | 248 | ||
218 | int | 249 | int |
... | @@ -231,8 +262,9 @@ main (int argc, char **argv) | ... | @@ -231,8 +262,9 @@ main (int argc, char **argv) |
231 | exit (1); | 262 | exit (1); |
232 | } | 263 | } |
233 | 264 | ||
234 | if (!draft_folder) | 265 | if (!wh_env.draftfolder) |
235 | draft_folder = mh_global_profile_get ("Draft-Folder", mu_path_folder_dir); | 266 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", |
267 | mu_path_folder_dir); | ||
236 | 268 | ||
237 | mbox = mh_open_folder (current_folder, 0); | 269 | mbox = mh_open_folder (current_folder, 0); |
238 | mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); | 270 | mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); |
... | @@ -242,9 +274,13 @@ main (int argc, char **argv) | ... | @@ -242,9 +274,13 @@ main (int argc, char **argv) |
242 | return 1; | 274 | return 1; |
243 | } | 275 | } |
244 | 276 | ||
245 | draft_file = mh_expand_name (draft_folder, "reply", 0); | 277 | wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0); |
246 | 278 | ||
247 | make_draft (); | 279 | make_draft (); |
248 | 280 | ||
249 | return 0; | 281 | /* Exit immediately if --build is given */ |
282 | if (build_only) | ||
283 | return 0; | ||
284 | |||
285 | return mh_whatnow (&wh_env, initial_edit); | ||
250 | } | 286 | } | ... | ... |
-
Please register or sign in to post a comment