Commit 6c7f202f 6c7f202ff7fd897c0952828ec1caed6c5c577053 by Sergey Poznyakoff

Implemented --annotate

1 parent 81d25f12
...@@ -31,7 +31,7 @@ static char args_doc[] = "[msgs]"; ...@@ -31,7 +31,7 @@ static char args_doc[] = "[msgs]";
31 /* GNU options */ 31 /* GNU options */
32 static struct argp_option options[] = { 32 static struct argp_option options[] = {
33 {"annotate", ARG_ANNOTATE, N_("BOOL"), OPTION_ARG_OPTIONAL, 33 {"annotate", ARG_ANNOTATE, N_("BOOL"), OPTION_ARG_OPTIONAL,
34 N_("* Add Replied: header to the message being replied to")}, 34 N_("Add Forwarded: header to each forwarded message")},
35 {"build", ARG_BUILD, 0, 0, 35 {"build", ARG_BUILD, 0, 0,
36 N_("Build the draft and quit immediately")}, 36 N_("Build the draft and quit immediately")},
37 {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, 37 {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0,
...@@ -107,6 +107,7 @@ struct mh_whatnow_env wh_env = { 0 }; ...@@ -107,6 +107,7 @@ struct mh_whatnow_env wh_env = { 0 };
107 static int initial_edit = 1; 107 static int initial_edit = 1;
108 static char *mhl_filter = NULL; /* --filter flag */ 108 static char *mhl_filter = NULL; /* --filter flag */
109 static int build_only = 0; /* --build flag */ 109 static int build_only = 0; /* --build flag */
110 static int annotate = 0; /* --annotate flag */
110 static enum encap_type encap = encap_clear; /* controlled by --format, --form 111 static enum encap_type encap = encap_clear; /* controlled by --format, --form
111 and --mime flags */ 112 and --mime flags */
112 static int use_draft = 0; /* --use flag */ 113 static int use_draft = 0; /* --use flag */
...@@ -120,6 +121,10 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) ...@@ -120,6 +121,10 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
120 { 121 {
121 switch (key) 122 switch (key)
122 { 123 {
124 case ARG_ANNOTATE:
125 annotate = is_true (arg);
126 break;
127
123 case ARG_BUILD: 128 case ARG_BUILD:
124 build_only = 1; 129 build_only = 1;
125 break; 130 break;
...@@ -189,7 +194,6 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) ...@@ -189,7 +194,6 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
189 encap = encap_clear; 194 encap = encap_clear;
190 break; 195 break;
191 196
192 case ARG_ANNOTATE:
193 case ARG_INPLACE: 197 case ARG_INPLACE:
194 case ARG_WHATNOWPROC: 198 case ARG_WHATNOWPROC:
195 case ARG_NOWHATNOWPROC: 199 case ARG_NOWHATNOWPROC:
...@@ -238,6 +242,9 @@ format_message (mu_mailbox_t mbox, mu_message_t msg, size_t num, void *data) ...@@ -238,6 +242,9 @@ format_message (mu_mailbox_t mbox, mu_message_t msg, size_t num, void *data)
238 char *s; 242 char *s;
239 int rc; 243 int rc;
240 244
245 if (annotate)
246 mu_list_append (wh_env.anno_list, msg);
247
241 if (fp->num) 248 if (fp->num)
242 { 249 {
243 asprintf (&s, "\n------- Message %d\n", fp->num++); 250 asprintf (&s, "\n------- Message %d\n", fp->num++);
...@@ -289,6 +296,12 @@ finish_draft () ...@@ -289,6 +296,12 @@ finish_draft ()
289 296
290 mu_stream_seek (stream, 0, SEEK_END); 297 mu_stream_seek (stream, 0, SEEK_END);
291 298
299 if (annotate)
300 {
301 wh_env.anno_field = "Forwarded";
302 mu_list_create (&wh_env.anno_list);
303 }
304
292 if (encap == encap_mime) 305 if (encap == encap_mime)
293 { 306 {
294 mu_url_t url; 307 mu_url_t url;
...@@ -310,6 +323,8 @@ finish_draft () ...@@ -310,6 +323,8 @@ finish_draft ()
310 size_t num; 323 size_t num;
311 324
312 mu_mailbox_get_message (mbox, msgset.list[i], &msg); 325 mu_mailbox_get_message (mbox, msgset.list[i], &msg);
326 if (annotate)
327 mu_list_append (wh_env.anno_list, msg);
313 mh_message_number (msg, &num); 328 mh_message_number (msg, &num);
314 snprintf (buf, sizeof buf, " %lu", (unsigned long) num); 329 snprintf (buf, sizeof buf, " %lu", (unsigned long) num);
315 rc = mu_stream_sequential_write (stream, buf, strlen (buf)); 330 rc = mu_stream_sequential_write (stream, buf, strlen (buf));
...@@ -355,7 +370,7 @@ finish_draft () ...@@ -355,7 +370,7 @@ finish_draft ()
355 int 370 int
356 main (int argc, char **argv) 371 main (int argc, char **argv)
357 { 372 {
358 int index; 373 int index, rc;
359 374
360 /* Native Language Support */ 375 /* Native Language Support */
361 mu_init_nls (); 376 mu_init_nls ();
...@@ -402,5 +417,10 @@ main (int argc, char **argv) ...@@ -402,5 +417,10 @@ main (int argc, char **argv)
402 return 0; 417 return 0;
403 } 418 }
404 419
405 return mh_whatnow (&wh_env, initial_edit); 420 rc = mh_whatnow (&wh_env, initial_edit);
421
422 mu_mailbox_save_attributes (mbox);
423 mu_mailbox_close (mbox);
424 mu_mailbox_destroy (&mbox);
425 return rc;
406 } 426 }
......
...@@ -34,7 +34,7 @@ static char args_doc[] = N_("[+folder] [msg]"); ...@@ -34,7 +34,7 @@ static char args_doc[] = N_("[+folder] [msg]");
34 /* GNU options */ 34 /* GNU options */
35 static struct argp_option options[] = { 35 static struct argp_option options[] = {
36 {"annotate", ARG_ANNOTATE, N_("BOOL"), OPTION_ARG_OPTIONAL, 36 {"annotate", ARG_ANNOTATE, N_("BOOL"), OPTION_ARG_OPTIONAL,
37 N_("* Add Replied: header to the message being replied to")}, 37 N_("Add Replied: header to the message being replied to")},
38 {"build", ARG_BUILD, 0, 0, 38 {"build", ARG_BUILD, 0, 0,
39 N_("Build the draft and quit immediately.")}, 39 N_("Build the draft and quit immediately.")},
40 {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, 40 {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0,
...@@ -121,6 +121,7 @@ static int build_only = 0; /* --build flag */ ...@@ -121,6 +121,7 @@ static int build_only = 0; /* --build flag */
121 static int query_mode = 0; /* --query flag */ 121 static int query_mode = 0; /* --query flag */
122 static int use_draft = 0; /* --use flag */ 122 static int use_draft = 0; /* --use flag */
123 static char *mhl_filter = NULL; /* --filter flag */ 123 static char *mhl_filter = NULL; /* --filter flag */
124 static int annotate; /* --annotate flag */
124 125
125 static int 126 static int
126 decode_cc_flag (const char *opt, const char *arg) 127 decode_cc_flag (const char *opt, const char *arg)
...@@ -141,6 +142,10 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) ...@@ -141,6 +142,10 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
141 142
142 switch (key) 143 switch (key)
143 { 144 {
145 case ARG_ANNOTATE:
146 annotate = is_true (arg);
147 break;
148
144 case ARG_BUILD: 149 case ARG_BUILD:
145 build_only = 1; 150 build_only = 1;
146 break; 151 break;
...@@ -231,7 +236,6 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) ...@@ -231,7 +236,6 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
231 mhl_filter = NULL; 236 mhl_filter = NULL;
232 break; 237 break;
233 238
234 case ARG_ANNOTATE:
235 case ARG_FCC: 239 case ARG_FCC:
236 case ARG_INPLACE: 240 case ARG_INPLACE:
237 case ARG_WHATNOWPROC: 241 case ARG_WHATNOWPROC:
...@@ -300,6 +304,12 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) ...@@ -300,6 +304,12 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
300 mu_strerror (rc)); 304 mu_strerror (rc));
301 exit (1); 305 exit (1);
302 } 306 }
307 if (annotate)
308 {
309 wh->anno_field = "Replied";
310 mu_list_create (&wh->anno_list);
311 mu_list_append (wh->anno_list, msg);
312 }
303 313
304 if (disp == DISP_REPLACE) 314 if (disp == DISP_REPLACE)
305 { 315 {
...@@ -360,7 +370,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) ...@@ -360,7 +370,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
360 int 370 int
361 main (int argc, char **argv) 371 main (int argc, char **argv)
362 { 372 {
363 int index; 373 int index, rc;
364 374
365 /* Native Language Support */ 375 /* Native Language Support */
366 mu_init_nls (); 376 mu_init_nls ();
...@@ -395,5 +405,10 @@ main (int argc, char **argv) ...@@ -395,5 +405,10 @@ main (int argc, char **argv)
395 if (build_only) 405 if (build_only)
396 return 0; 406 return 0;
397 407
398 return mh_whatnow (&wh_env, initial_edit); 408 rc = mh_whatnow (&wh_env, initial_edit);
409
410 mu_mailbox_save_attributes (mbox);
411 mu_mailbox_close (mbox);
412 mu_mailbox_destroy (&mbox);
413 return rc;
399 } 414 }
......