diff options
| author | Richard M. Stallman | 1997-01-21 01:54:39 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-01-21 01:54:39 +0000 |
| commit | fea4325c82ba335c4e3d7c4edc9b7c5534a6c0da (patch) | |
| tree | 4dd49ca510475af91c211c912ac890ea83f22c81 /lib-src | |
| parent | 4144e5cba0fe2b99da2f04a239462269169168a4 (diff) | |
| download | emacs-fea4325c82ba335c4e3d7c4edc9b7c5534a6c0da.tar.gz emacs-fea4325c82ba335c4e3d7c4edc9b7c5534a6c0da.zip | |
(main): Do not display "[POP-password]" in the usage
message when movemail is compiled without POP support.
(main, popmail): Add the optional "-p" argument, which causes
movemail to leave mail in the inbox after copying it into the
output file.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/movemail.c | 83 |
1 files changed, 59 insertions, 24 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index add3ab7e11d..6031d26ea4f 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -62,6 +62,7 @@ Boston, MA 02111-1307, USA. */ | |||
| 62 | #include <stdio.h> | 62 | #include <stdio.h> |
| 63 | #include <errno.h> | 63 | #include <errno.h> |
| 64 | #include <../src/syswait.h> | 64 | #include <../src/syswait.h> |
| 65 | #include <getopt.h> | ||
| 65 | #ifdef MAIL_USE_POP | 66 | #ifdef MAIL_USE_POP |
| 66 | #include "pop.h" | 67 | #include "pop.h" |
| 67 | #endif | 68 | #endif |
| @@ -167,6 +168,7 @@ main (argc, argv) | |||
| 167 | int indesc, outdesc; | 168 | int indesc, outdesc; |
| 168 | int nread; | 169 | int nread; |
| 169 | WAITTYPE status; | 170 | WAITTYPE status; |
| 171 | int c, preserve_mail = 0; | ||
| 170 | 172 | ||
| 171 | #ifndef MAIL_USE_SYSTEM_LOCK | 173 | #ifndef MAIL_USE_SYSTEM_LOCK |
| 172 | struct stat st; | 174 | struct stat st; |
| @@ -183,14 +185,37 @@ main (argc, argv) | |||
| 183 | 185 | ||
| 184 | delete_lockname = 0; | 186 | delete_lockname = 0; |
| 185 | 187 | ||
| 186 | if (argc < 3) | 188 | while ((c = getopt (argc, argv, "p")) != EOF) |
| 187 | { | 189 | { |
| 188 | fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n"); | 190 | switch (c) { |
| 191 | case 'p': | ||
| 192 | preserve_mail++; | ||
| 193 | break; | ||
| 194 | default: | ||
| 195 | exit(1); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | if ( | ||
| 200 | #ifdef MAIL_USE_POP | ||
| 201 | (argc - optind < 2) || (argc - optind > 3) | ||
| 202 | #else | ||
| 203 | (argc - optind != 2) | ||
| 204 | #endif | ||
| 205 | ) | ||
| 206 | { | ||
| 207 | fprintf (stderr, "Usage: movemail [-p] inbox destfile%s\n", | ||
| 208 | #ifdef MAIL_USE_POP | ||
| 209 | " [POP-password]" | ||
| 210 | #else | ||
| 211 | "" | ||
| 212 | #endif | ||
| 213 | ); | ||
| 189 | exit (1); | 214 | exit (1); |
| 190 | } | 215 | } |
| 191 | 216 | ||
| 192 | inname = argv[1]; | 217 | inname = argv[optind]; |
| 193 | outname = argv[2]; | 218 | outname = argv[optind+1]; |
| 194 | 219 | ||
| 195 | #ifdef MAIL_USE_MMDF | 220 | #ifdef MAIL_USE_MMDF |
| 196 | mmdf_init (argv[0]); | 221 | mmdf_init (argv[0]); |
| @@ -223,7 +248,8 @@ main (argc, argv) | |||
| 223 | { | 248 | { |
| 224 | int status; | 249 | int status; |
| 225 | 250 | ||
| 226 | status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL); | 251 | status = popmail (inname + 3, outname, preserve_mail, |
| 252 | (argc - optind == 3) ? argv[optind+2] : NULL); | ||
| 227 | exit (status); | 253 | exit (status); |
| 228 | } | 254 | } |
| 229 | 255 | ||
| @@ -448,11 +474,15 @@ main (argc, argv) | |||
| 448 | pfatal_and_delete (outname); | 474 | pfatal_and_delete (outname); |
| 449 | 475 | ||
| 450 | #ifdef MAIL_USE_SYSTEM_LOCK | 476 | #ifdef MAIL_USE_SYSTEM_LOCK |
| 477 | if (! preserve_mail) | ||
| 478 | { | ||
| 451 | #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT) | 479 | #if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT) |
| 452 | /* Stride, xenix have file locking, but no ftruncate. This mess will do. */ | 480 | /* Stride, xenix have file locking, but no ftruncate. |
| 453 | close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); | 481 | This mess will do. */ |
| 482 | close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666)); | ||
| 454 | #else | 483 | #else |
| 455 | ftruncate (indesc, 0L); | 484 | ftruncate (indesc, 0L); |
| 485 | } | ||
| 456 | #endif /* STRIDE or XENIX */ | 486 | #endif /* STRIDE or XENIX */ |
| 457 | #endif /* MAIL_USE_SYSTEM_LOCK */ | 487 | #endif /* MAIL_USE_SYSTEM_LOCK */ |
| 458 | 488 | ||
| @@ -463,14 +493,17 @@ main (argc, argv) | |||
| 463 | #endif | 493 | #endif |
| 464 | 494 | ||
| 465 | #ifndef MAIL_USE_SYSTEM_LOCK | 495 | #ifndef MAIL_USE_SYSTEM_LOCK |
| 466 | /* Delete the input file; if we can't, at least get rid of its | 496 | if (! preserve_mail) |
| 467 | contents. */ | 497 | { |
| 498 | /* Delete the input file; if we can't, at least get rid of its | ||
| 499 | contents. */ | ||
| 468 | #ifdef MAIL_UNLINK_SPOOL | 500 | #ifdef MAIL_UNLINK_SPOOL |
| 469 | /* This is generally bad to do, because it destroys the permissions | 501 | /* This is generally bad to do, because it destroys the permissions |
| 470 | that were set on the file. Better to just empty the file. */ | 502 | that were set on the file. Better to just empty the file. */ |
| 471 | if (unlink (inname) < 0 && errno != ENOENT) | 503 | if (unlink (inname) < 0 && errno != ENOENT) |
| 472 | #endif /* MAIL_UNLINK_SPOOL */ | 504 | #endif /* MAIL_UNLINK_SPOOL */ |
| 473 | creat (inname, 0600); | 505 | creat (inname, 0600); |
| 506 | } | ||
| 474 | #endif /* not MAIL_USE_SYSTEM_LOCK */ | 507 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 475 | 508 | ||
| 476 | #ifdef MAIL_USE_MAILLOCK | 509 | #ifdef MAIL_USE_MAILLOCK |
| @@ -644,9 +677,10 @@ char ibuffer[BUFSIZ]; | |||
| 644 | char obuffer[BUFSIZ]; | 677 | char obuffer[BUFSIZ]; |
| 645 | char Errmsg[80]; | 678 | char Errmsg[80]; |
| 646 | 679 | ||
| 647 | popmail (user, outfile, password) | 680 | popmail (user, outfile, preserve, password) |
| 648 | char *user; | 681 | char *user; |
| 649 | char *outfile; | 682 | char *outfile; |
| 683 | int preserve; | ||
| 650 | char *password; | 684 | char *password; |
| 651 | { | 685 | { |
| 652 | int nmsgs, nbytes; | 686 | int nmsgs, nbytes; |
| @@ -735,15 +769,16 @@ popmail (user, outfile, password) | |||
| 735 | return (1); | 769 | return (1); |
| 736 | } | 770 | } |
| 737 | 771 | ||
| 738 | for (i = 1; i <= nmsgs; i++) | 772 | if (! preserve) |
| 739 | { | 773 | for (i = 1; i <= nmsgs; i++) |
| 740 | if (pop_delete (server, i)) | 774 | { |
| 741 | { | 775 | if (pop_delete (server, i)) |
| 742 | error (pop_error); | 776 | { |
| 743 | pop_close (server); | 777 | error (pop_error); |
| 744 | return (1); | 778 | pop_close (server); |
| 745 | } | 779 | return (1); |
| 746 | } | 780 | } |
| 781 | } | ||
| 747 | 782 | ||
| 748 | if (pop_quit (server)) | 783 | if (pop_quit (server)) |
| 749 | { | 784 | { |