Commit a2f3bd9d a2f3bd9d825be08f1eb922a327e047a154c0677d by Sergey Poznyakoff

Emacs-iteraction mode (--emacs)

1 parent f5e458e1
...@@ -29,16 +29,19 @@ const char *program_version = "movemail (" PACKAGE_STRING ")"; ...@@ -29,16 +29,19 @@ const char *program_version = "movemail (" PACKAGE_STRING ")";
29 static char doc[] = N_("GNU movemail"); 29 static char doc[] = N_("GNU movemail");
30 static char args_doc[] = N_("inbox-url destfile [POP-password]"); 30 static char args_doc[] = N_("inbox-url destfile [POP-password]");
31 31
32 #define OPT_EMACS 256
33
32 static struct argp_option options[] = { 34 static struct argp_option options[] = {
33 { "preserve", 'p', NULL, 0, N_("Preserve the source mailbox"), 0 }, 35 { "preserve", 'p', NULL, 0, N_("Preserve the source mailbox"), 0 },
34 { "keep-messages", 0, NULL, OPTION_ALIAS, NULL }, 36 { "keep-messages", 0, NULL, OPTION_ALIAS, NULL },
35 { "reverse", 'r', NULL, 0, N_("Reverse the sorting order"), 0 }, 37 { "reverse", 'r', NULL, 0, N_("Reverse the sorting order"), 0 },
36 38 { "emacs", OPT_EMACS, NULL, 0, N_("Output information used by Emacs rmail interface"), 0 },
37 { NULL, 0, NULL, 0, NULL, 0 } 39 { NULL, 0, NULL, 0, NULL, 0 }
38 }; 40 };
39 41
40 static int reverse_order; 42 static int reverse_order;
41 static int preserve_mail; 43 static int preserve_mail;
44 static int emacs_mode;
42 45
43 static error_t 46 static error_t
44 parse_opt (int key, char *arg, struct argp_state *state) 47 parse_opt (int key, char *arg, struct argp_state *state)
...@@ -53,6 +56,10 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -53,6 +56,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
53 preserve_mail++; 56 preserve_mail++;
54 break; 57 break;
55 58
59 case OPT_EMACS:
60 emacs_mode++;
61 break;
62
56 default: 63 default:
57 return ARGP_ERR_UNKNOWN; 64 return ARGP_ERR_UNKNOWN;
58 } 65 }
...@@ -78,12 +85,30 @@ static const char *mail_capa[] = { ...@@ -78,12 +85,30 @@ static const char *mail_capa[] = {
78 NULL 85 NULL
79 }; 86 };
80 87
88 int
89 movemail_error_printer (const char *fmt, va_list ap)
90 {
91 int n;
92
93 n = fprintf (stderr, "%s: ", program_invocation_short_name);
94 n += vfprintf (stderr, fmt, ap);
95 fputc ('\n', stderr);
96 return n + 1;
97 }
98
81 void 99 void
82 die (mailbox_t mbox, char *msg, int status) 100 die (mailbox_t mbox, char *msg, int status)
83 { 101 {
84 url_t url = NULL; 102 url_t url = NULL;
85 103
86 mailbox_get_url (mbox, &url); 104 mailbox_get_url (mbox, &url);
105 if (emacs_mode)
106 mu_error (_("%s:mailbox '%s': %s: %s"),
107 mu_errname (status),
108 url_to_string (url),
109 msg,
110 mu_strerror (status));
111 else
87 mu_error (_("mailbox '%s': %s: %s"), 112 mu_error (_("mailbox '%s': %s: %s"),
88 url_to_string (url), msg, mu_strerror (status)); 113 url_to_string (url), msg, mu_strerror (status));
89 exit (1); 114 exit (1);
...@@ -227,16 +252,6 @@ compatibility_mode (mailbox_t *mbx, char *source_name, char *password, ...@@ -227,16 +252,6 @@ compatibility_mode (mailbox_t *mbx, char *source_name, char *password,
227 } 252 }
228 253
229 int 254 int
230 movemail_error_printer (const char *fmt, va_list ap)
231 {
232 int n;
233 n = fprintf (stderr, "%s: ", program_invocation_short_name);
234 n += vfprintf (stderr, fmt, ap);
235 fputc ('\n', stderr);
236 return n + 1;
237 }
238
239 int
240 main (int argc, char **argv) 255 main (int argc, char **argv)
241 { 256 {
242 int index; 257 int index;
......