Commit 36656d1f 36656d1f5af44810ca63fe3c97c7a56c0bc19173 by Sergey Poznyakoff

Fix hex (%XX) expansion in URLs.

* mailbox/url.c (url_parse0): Take three arguments.  Return in the
third one a boolean indicating whether to expand %XX notations in
the URL.  Do not decode absolute file names and pipes.
(mu_url_parse): Use this value to decide.
* movemail/movemail.c (main): In emacs mode: force UNIX mbox
format as a default.  Send debugging output to stderr.
* libmailutils/tests/url.at: Add new tests.
1 parent c42bddb0
...@@ -24,7 +24,7 @@ m4_pushdef([TESTURL],[ ...@@ -24,7 +24,7 @@ m4_pushdef([TESTURL],[
24 m4_pushdef([MU_TEST_GROUP],[Url]) 24 m4_pushdef([MU_TEST_GROUP],[Url])
25 m4_pushdef([MU_TEST_KEYWORDS],[url]) 25 m4_pushdef([MU_TEST_KEYWORDS],[url])
26 m4_pushdef([MU_TEST_COMMAND],[url-parse]) 26 m4_pushdef([MU_TEST_COMMAND],[url-parse])
27 MU_GENERIC_TEST([$1],[$2],[$3],[],[$4],[$5]) 27 MU_GENERIC_TEST([$1],[$2 url-m4_translit($3,[ ],[_])],[$3],[],[$4],[$5])
28 m4_popdef([MU_TEST_COMMAND]) 28 m4_popdef([MU_TEST_COMMAND])
29 m4_popdef([MU_TEST_KEYWORDS]) 29 m4_popdef([MU_TEST_KEYWORDS])
30 m4_popdef([MU_TEST_GROUP]) 30 m4_popdef([MU_TEST_GROUP])
...@@ -774,4 +774,40 @@ query[1] <arg 1> ...@@ -774,4 +774,40 @@ query[1] <arg 1>
774 query[2] <arg 2> 774 query[2] <arg 2>
775 ]]) 775 ]])
776 776
777 TESTURL([],[],
778 [/usr/sbin/sendmail],
779 [scheme <file>
780 user <>
781 passwd <>
782 auth <>
783 host <>
784 port 0
785 path </usr/sbin/sendmail>
786 ])
787
788 TESTURL([],[],
789 [/var/spool/mail/gray%40gnu.org],
790 [scheme <file>
791 user <>
792 passwd <>
793 auth <>
794 host <>
795 port 0
796 path </var/spool/mail/gray%40gnu.org>
797 ])
798
799 TESTURL([],[],
800 [| /bin/mailman request list%40dom],
801 [[scheme <prog>
802 user <>
803 passwd <>
804 auth <>
805 host <>
806 port 0
807 path </bin/mailman>
808 query[0] </bin/mailman>
809 query[1] <request>
810 query[2] <list%40dom>
811 ]])
812
777 m4_popdef([TESTURL]) 813 m4_popdef([TESTURL])
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
40 #define AC2(a,b) a ## b 40 #define AC2(a,b) a ## b
41 #define AC4(a,b,c,d) a ## b ## c ## d 41 #define AC4(a,b,c,d) a ## b ## c ## d
42 42
43 static int url_parse0 (mu_url_t, char *, size_t *poff); 43 static int url_parse0 (mu_url_t, char *, size_t *poff, int *decode);
44 44
45 static int 45 static int
46 parse_query (const char *query, 46 parse_query (const char *query,
...@@ -286,6 +286,7 @@ mu_url_parse (mu_url_t url) ...@@ -286,6 +286,7 @@ mu_url_parse (mu_url_t url)
286 struct _mu_url u; 286 struct _mu_url u;
287 size_t pstart; 287 size_t pstart;
288 mu_secret_t newsec; 288 mu_secret_t newsec;
289 int want_decode;
289 290
290 if (!url || !url->name) 291 if (!url || !url->name)
291 return EINVAL; 292 return EINVAL;
...@@ -301,7 +302,7 @@ mu_url_parse (mu_url_t url) ...@@ -301,7 +302,7 @@ mu_url_parse (mu_url_t url)
301 if (!n) 302 if (!n)
302 return ENOMEM; 303 return ENOMEM;
303 304
304 err = url_parse0 (&u, n, &pstart); 305 err = url_parse0 (&u, n, &pstart, &want_decode);
305 306
306 if (!err) 307 if (!err)
307 { 308 {
...@@ -332,7 +333,8 @@ mu_url_parse (mu_url_t url) ...@@ -332,7 +333,8 @@ mu_url_parse (mu_url_t url)
332 */ 333 */
333 334
334 #define UALLOC(X) \ 335 #define UALLOC(X) \
335 if (u.X && u.X[0] && (url->X = mu_url_decode(u.X)) == 0) \ 336 if (u.X && u.X[0] && \
337 !(url->X = (want_decode ? mu_url_decode (u.X) : strdup (u.X)))) \
336 { \ 338 { \
337 err = ENOMEM; \ 339 err = ENOMEM; \
338 goto CLEANUP; \ 340 goto CLEANUP; \
...@@ -420,7 +422,7 @@ Is this required to be % quoted, though? I hope so! ...@@ -420,7 +422,7 @@ Is this required to be % quoted, though? I hope so!
420 */ 422 */
421 423
422 static int 424 static int
423 url_parse0 (mu_url_t u, char *name, size_t *poff) 425 url_parse0 (mu_url_t u, char *name, size_t *poff, int *decode)
424 { 426 {
425 char *start = name; 427 char *start = name;
426 char *p; /* pointer into name */ 428 char *p; /* pointer into name */
...@@ -432,11 +434,13 @@ url_parse0 (mu_url_t u, char *name, size_t *poff) ...@@ -432,11 +434,13 @@ url_parse0 (mu_url_t u, char *name, size_t *poff)
432 if (name[0] == '/') 434 if (name[0] == '/')
433 { 435 {
434 u->scheme = "file"; 436 u->scheme = "file";
437 *decode = 0;
435 } 438 }
436 else if (name[0] == '|') 439 else if (name[0] == '|')
437 { 440 {
438 int rc; 441 int rc;
439 u->scheme = "prog"; 442 u->scheme = "prog";
443 *decode = 0;
440 rc = mu_argcv_get (name + 1, NULL, NULL, &u->qargc, &u->qargv); 444 rc = mu_argcv_get (name + 1, NULL, NULL, &u->qargc, &u->qargv);
441 if (rc == 0) 445 if (rc == 0)
442 { 446 {
...@@ -448,6 +452,7 @@ url_parse0 (mu_url_t u, char *name, size_t *poff) ...@@ -448,6 +452,7 @@ url_parse0 (mu_url_t u, char *name, size_t *poff)
448 } 452 }
449 else 453 else
450 { 454 {
455 *decode = 1;
451 /* Parse out the SCHEME. */ 456 /* Parse out the SCHEME. */
452 p = strchr (name, ':'); 457 p = strchr (name, ':');
453 if (p == NULL) 458 if (p == NULL)
......
...@@ -759,6 +759,14 @@ main (int argc, char **argv) ...@@ -759,6 +759,14 @@ main (int argc, char **argv)
759 return 1; 759 return 1;
760 } 760 }
761 761
762 if (emacs_mode)
763 {
764 /* Undo the effect of configuration options that may affect
765 the interaction with Emacs. */
766 mu_registrar_set_default_record (mu_mbox_record);
767 mu_debug_default_printer = mu_debug_stderr_printer;
768 }
769
762 atexit (close_mailboxes); 770 atexit (close_mailboxes);
763 771
764 source_name = argv[0]; 772 source_name = argv[0];
......