Commit c76105b7 c76105b76ccdeb5fdd0516210e7f4bbe4f36d52f by Sergey Poznyakoff

Allow to use traditional Emacs

invocation (password as the last argument) with usual
Mailutils URLs.
1 parent 3a3f2015
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
27 27
28 const char *program_version = "movemail (" PACKAGE_STRING ")"; 28 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 destfile [POP-password]"); 30 static char args_doc[] = N_("inbox-url destfile [POP-password]");
31 31
32 static struct argp_option options[] = { 32 static struct argp_option options[] = {
33 { "preserve", 'p', NULL, 0, N_("Preserve the source mailbox"), 0 }, 33 { "preserve", 'p', NULL, 0, N_("Preserve the source mailbox"), 0 },
...@@ -103,16 +103,57 @@ lock_mailbox (mailbox_t mbox) ...@@ -103,16 +103,57 @@ lock_mailbox (mailbox_t mbox)
103 /* Remote mailboxes have no lockers */ 103 /* Remote mailboxes have no lockers */
104 return; 104 return;
105 105
106 /* FIXME: locker_set_retries (lock, lock_timeout); */
107
108 status = locker_lock (lock); 106 status = locker_lock (lock);
109 107
110 if (status) 108 if (status)
111 die (mbox, _("Cannot lock"), status); 109 die (mbox, _("Cannot lock"), status);
112 } 110 }
113 111
112
113 /* A password ticket: returns the cleantext password. */
114 void
115 password_destroy (ticket_t t)
116 {
117 char *p = ticket_get_owner (t);
118 free (p);
119 }
120
121 int
122 password_pop (ticket_t t, url_t u, const char *challenge, char **ppwd)
123 {
124 char *p = ticket_get_owner (t);
125 *ppwd = strdup (p);
126 return 0;
127 }
128
114 void 129 void
115 open_mailbox (mailbox_t *mbx, char *name, int flags) 130 attach_passwd_ticket (mailbox_t mbx, char *passwd)
131 {
132 folder_t folder = NULL;
133 authority_t auth = NULL;
134 char *p = strdup (passwd);
135 ticket_t t;
136 int rc;
137
138 ticket_create (&t, p);
139 ticket_set_destroy (t, password_destroy, p);
140 ticket_set_pop (t, password_pop, p);
141
142 if ((rc = mailbox_get_folder (mbx, &folder)))
143 die (mbx, _("mailbox_get_folder failed"), rc);
144
145 if ((rc = folder_get_authority (folder, &auth)))
146 die (mbx, _("folder_get_authority failed"), rc);
147
148 if (auth && (rc = authority_set_ticket (auth, t)))
149 die (mbx, _("authority_set_ticket failed"), rc);
150 }
151
152
153 /* Create and open a mailbox associated with the given URL,
154 flags and (optionally) password */
155 void
156 open_mailbox (mailbox_t *mbx, char *name, int flags, char *passwd)
116 { 157 {
117 int status = mailbox_create_default (mbx, name); 158 int status = mailbox_create_default (mbx, name);
118 159
...@@ -124,6 +165,8 @@ open_mailbox (mailbox_t *mbx, char *name, int flags) ...@@ -124,6 +165,8 @@ open_mailbox (mailbox_t *mbx, char *name, int flags)
124 exit (1); 165 exit (1);
125 } 166 }
126 167
168 if (passwd)
169 attach_passwd_ticket (*mbx, passwd);
127 status = mailbox_open (*mbx, flags); 170 status = mailbox_open (*mbx, flags);
128 if (status) 171 if (status)
129 die (*mbx, _("cannot open"), status); 172 die (*mbx, _("cannot open"), status);
...@@ -176,11 +219,8 @@ compatibility_mode (mailbox_t *mbx, char *source_name, char *password, ...@@ -176,11 +219,8 @@ compatibility_mode (mailbox_t *mbx, char *source_name, char *password,
176 mu_error (_("Hostname of the POP3 server is unknown")); 219 mu_error (_("Hostname of the POP3 server is unknown"));
177 exit (1); 220 exit (1);
178 } 221 }
179 if (password) 222 asprintf (&tmp, "pop://%s@%s", user_name, host);
180 asprintf (&tmp, "pop://%s:%s@%s", user_name, password, host); 223 open_mailbox (mbx, tmp, flags, password);
181 else
182 asprintf (&tmp, "pop://%s@%s", user_name, host);
183 open_mailbox (mbx, tmp, flags);
184 free (tmp); 224 free (tmp);
185 } 225 }
186 226
...@@ -245,10 +285,10 @@ main (int argc, char **argv) ...@@ -245,10 +285,10 @@ main (int argc, char **argv)
245 285
246 if (strncmp (source_name, "po:", 3) == 0) 286 if (strncmp (source_name, "po:", 3) == 0)
247 compatibility_mode (&source, source_name, argv[2], flags); 287 compatibility_mode (&source, source_name, argv[2], flags);
248 else 288 else
249 open_mailbox (&source, source_name, flags); 289 open_mailbox (&source, source_name, flags, argv[2]);
250 290
251 open_mailbox (&dest, dest_name, MU_STREAM_RDWR | MU_STREAM_CREAT); 291 open_mailbox (&dest, dest_name, MU_STREAM_RDWR | MU_STREAM_CREAT, NULL);
252 292
253 mailbox_messages_count (source, &total); 293 mailbox_messages_count (source, &total);
254 if (reverse_order) 294 if (reverse_order)
......