diff options
Diffstat (limited to 'lib-src/movemail.c')
| -rw-r--r-- | lib-src/movemail.c | 111 |
1 files changed, 45 insertions, 66 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index ea307241351..541edf545df 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -69,6 +69,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 69 | #ifdef HAVE_FCNTL_H | 69 | #ifdef HAVE_FCNTL_H |
| 70 | #include <fcntl.h> | 70 | #include <fcntl.h> |
| 71 | #endif | 71 | #endif |
| 72 | #ifdef HAVE_STRING_H | ||
| 73 | #include <string.h> | ||
| 74 | #endif | ||
| 72 | #include "syswait.h" | 75 | #include "syswait.h" |
| 73 | #ifdef MAIL_USE_POP | 76 | #ifdef MAIL_USE_POP |
| 74 | #include "pop.h" | 77 | #include "pop.h" |
| @@ -140,33 +143,29 @@ static char *mail_spool_name (); | |||
| 140 | #endif | 143 | #endif |
| 141 | #endif | 144 | #endif |
| 142 | 145 | ||
| 143 | char *strerror (); | 146 | #ifndef HAVE_STRERROR |
| 144 | #ifdef HAVE_INDEX | 147 | char *strerror (int); |
| 145 | extern char *index __P ((const char *, int)); | ||
| 146 | #endif | ||
| 147 | #ifdef HAVE_RINDEX | ||
| 148 | extern char *rindex __P((const char *, int)); | ||
| 149 | #endif | 148 | #endif |
| 150 | 149 | ||
| 151 | void fatal (); | 150 | static void fatal (char *s1, char *s2, char *s3); |
| 152 | void error (); | 151 | static void error (char *s1, char *s2, char *s3); |
| 153 | void pfatal_with_name (); | 152 | static void pfatal_with_name (char *name); |
| 154 | void pfatal_and_delete (); | 153 | static void pfatal_and_delete (char *name); |
| 155 | char *concat (); | 154 | static char *concat (char *s1, char *s2, char *s3); |
| 156 | long *xmalloc (); | 155 | static long *xmalloc (unsigned int size); |
| 157 | int popmail (); | 156 | #ifdef MAIL_USE_POP |
| 158 | int pop_retr (); | 157 | static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order); |
| 159 | int mbx_write (); | 158 | static int pop_retr (popserver server, int msgno, FILE *arg); |
| 160 | int mbx_delimit_begin (); | 159 | static int mbx_write (char *line, int len, FILE *mbf); |
| 161 | int mbx_delimit_end (); | 160 | static int mbx_delimit_begin (FILE *mbf); |
| 161 | static int mbx_delimit_end (FILE *mbf); | ||
| 162 | #endif | ||
| 162 | 163 | ||
| 163 | /* Nonzero means this is name of a lock file to delete on fatal error. */ | 164 | /* Nonzero means this is name of a lock file to delete on fatal error. */ |
| 164 | char *delete_lockname; | 165 | char *delete_lockname; |
| 165 | 166 | ||
| 166 | int | 167 | int |
| 167 | main (argc, argv) | 168 | main (int argc, char **argv) |
| 168 | int argc; | ||
| 169 | char **argv; | ||
| 170 | { | 169 | { |
| 171 | char *inname, *outname; | 170 | char *inname, *outname; |
| 172 | int indesc, outdesc; | 171 | int indesc, outdesc; |
| @@ -559,7 +558,7 @@ mail_spool_name (inname) | |||
| 559 | char *indir, *fname; | 558 | char *indir, *fname; |
| 560 | int status; | 559 | int status; |
| 561 | 560 | ||
| 562 | if (! (fname = rindex (inname, '/'))) | 561 | if (! (fname = strrchr (inname, '/'))) |
| 563 | return NULL; | 562 | return NULL; |
| 564 | 563 | ||
| 565 | fname++; | 564 | fname++; |
| @@ -589,9 +588,8 @@ mail_spool_name (inname) | |||
| 589 | 588 | ||
| 590 | /* Print error message and exit. */ | 589 | /* Print error message and exit. */ |
| 591 | 590 | ||
| 592 | void | 591 | static void |
| 593 | fatal (s1, s2, s3) | 592 | fatal (char *s1, char *s2, char *s3) |
| 594 | char *s1, *s2, *s3; | ||
| 595 | { | 593 | { |
| 596 | if (delete_lockname) | 594 | if (delete_lockname) |
| 597 | unlink (delete_lockname); | 595 | unlink (delete_lockname); |
| @@ -602,9 +600,8 @@ fatal (s1, s2, s3) | |||
| 602 | /* Print error message. `s1' is printf control string, `s2' and `s3' | 600 | /* Print error message. `s1' is printf control string, `s2' and `s3' |
| 603 | are args for it or null. */ | 601 | are args for it or null. */ |
| 604 | 602 | ||
| 605 | void | 603 | static void |
| 606 | error (s1, s2, s3) | 604 | error (char *s1, char *s2, char *s3) |
| 607 | char *s1, *s2, *s3; | ||
| 608 | { | 605 | { |
| 609 | fprintf (stderr, "movemail: "); | 606 | fprintf (stderr, "movemail: "); |
| 610 | if (s3) | 607 | if (s3) |
| @@ -612,20 +609,18 @@ error (s1, s2, s3) | |||
| 612 | else if (s2) | 609 | else if (s2) |
| 613 | fprintf (stderr, s1, s2); | 610 | fprintf (stderr, s1, s2); |
| 614 | else | 611 | else |
| 615 | fprintf (stderr, s1); | 612 | fprintf (stderr, "%s", s1); |
| 616 | fprintf (stderr, "\n"); | 613 | fprintf (stderr, "\n"); |
| 617 | } | 614 | } |
| 618 | 615 | ||
| 619 | void | 616 | static void |
| 620 | pfatal_with_name (name) | 617 | pfatal_with_name (char *name) |
| 621 | char *name; | ||
| 622 | { | 618 | { |
| 623 | fatal ("%s for %s", strerror (errno), name); | 619 | fatal ("%s for %s", strerror (errno), name); |
| 624 | } | 620 | } |
| 625 | 621 | ||
| 626 | void | 622 | static void |
| 627 | pfatal_and_delete (name) | 623 | pfatal_and_delete (char *name) |
| 628 | char *name; | ||
| 629 | { | 624 | { |
| 630 | char *s = strerror (errno); | 625 | char *s = strerror (errno); |
| 631 | unlink (name); | 626 | unlink (name); |
| @@ -634,9 +629,8 @@ pfatal_and_delete (name) | |||
| 634 | 629 | ||
| 635 | /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ | 630 | /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ |
| 636 | 631 | ||
| 637 | char * | 632 | static char * |
| 638 | concat (s1, s2, s3) | 633 | concat (char *s1, char *s2, char *s3) |
| 639 | char *s1, *s2, *s3; | ||
| 640 | { | 634 | { |
| 641 | int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | 635 | int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); |
| 642 | char *result = (char *) xmalloc (len1 + len2 + len3 + 1); | 636 | char *result = (char *) xmalloc (len1 + len2 + len3 + 1); |
| @@ -651,9 +645,8 @@ concat (s1, s2, s3) | |||
| 651 | 645 | ||
| 652 | /* Like malloc but get fatal error if memory is exhausted. */ | 646 | /* Like malloc but get fatal error if memory is exhausted. */ |
| 653 | 647 | ||
| 654 | long * | 648 | static long * |
| 655 | xmalloc (size) | 649 | xmalloc (unsigned int size) |
| 656 | unsigned size; | ||
| 657 | { | 650 | { |
| 658 | long *result = (long *) malloc (size); | 651 | long *result = (long *) malloc (size); |
| 659 | if (!result) | 652 | if (!result) |
| @@ -702,25 +695,20 @@ char Errmsg[200]; /* POP errors, at least, can exceed | |||
| 702 | * Return a value suitable for passing to `exit'. | 695 | * Return a value suitable for passing to `exit'. |
| 703 | */ | 696 | */ |
| 704 | 697 | ||
| 705 | int | 698 | static int |
| 706 | popmail (mailbox, outfile, preserve, password, reverse_order) | 699 | popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order) |
| 707 | char *mailbox; | ||
| 708 | char *outfile; | ||
| 709 | int preserve; | ||
| 710 | char *password; | ||
| 711 | int reverse_order; | ||
| 712 | { | 700 | { |
| 713 | int nmsgs, nbytes; | 701 | int nmsgs, nbytes; |
| 714 | register int i; | 702 | register int i; |
| 715 | int mbfi; | 703 | int mbfi; |
| 716 | FILE *mbf; | 704 | FILE *mbf; |
| 717 | char *getenv (); | 705 | char *getenv (const char *); |
| 718 | popserver server; | 706 | popserver server; |
| 719 | int start, end, increment; | 707 | int start, end, increment; |
| 720 | char *user, *hostname; | 708 | char *user, *hostname; |
| 721 | 709 | ||
| 722 | user = mailbox; | 710 | user = mailbox; |
| 723 | if ((hostname = index(mailbox, ':'))) | 711 | if ((hostname = strchr (mailbox, ':'))) |
| 724 | *hostname++ = '\0'; | 712 | *hostname++ = '\0'; |
| 725 | 713 | ||
| 726 | server = pop_open (hostname, user, password, POP_NO_GETPASS); | 714 | server = pop_open (hostname, user, password, POP_NO_GETPASS); |
| @@ -833,13 +821,9 @@ popmail (mailbox, outfile, preserve, password, reverse_order) | |||
| 833 | return EXIT_SUCCESS; | 821 | return EXIT_SUCCESS; |
| 834 | } | 822 | } |
| 835 | 823 | ||
| 836 | int | 824 | static int |
| 837 | pop_retr (server, msgno, arg) | 825 | pop_retr (popserver server, int msgno, FILE *arg) |
| 838 | popserver server; | ||
| 839 | int msgno; | ||
| 840 | FILE *arg; | ||
| 841 | { | 826 | { |
| 842 | extern char *strerror (); | ||
| 843 | char *line; | 827 | char *line; |
| 844 | int ret; | 828 | int ret; |
| 845 | 829 | ||
| @@ -884,11 +868,8 @@ pop_retr (server, msgno, arg) | |||
| 884 | && (a[3] == 'm') \ | 868 | && (a[3] == 'm') \ |
| 885 | && (a[4] == ' ')) | 869 | && (a[4] == ' ')) |
| 886 | 870 | ||
| 887 | int | 871 | static int |
| 888 | mbx_write (line, len, mbf) | 872 | mbx_write (char *line, int len, FILE *mbf) |
| 889 | char *line; | ||
| 890 | int len; | ||
| 891 | FILE *mbf; | ||
| 892 | { | 873 | { |
| 893 | #ifdef MOVEMAIL_QUOTE_POP_FROM_LINES | 874 | #ifdef MOVEMAIL_QUOTE_POP_FROM_LINES |
| 894 | if (IS_FROM_LINE (line)) | 875 | if (IS_FROM_LINE (line)) |
| @@ -911,9 +892,8 @@ mbx_write (line, len, mbf) | |||
| 911 | return (OK); | 892 | return (OK); |
| 912 | } | 893 | } |
| 913 | 894 | ||
| 914 | int | 895 | static int |
| 915 | mbx_delimit_begin (mbf) | 896 | mbx_delimit_begin (FILE *mbf) |
| 916 | FILE *mbf; | ||
| 917 | { | 897 | { |
| 918 | time_t now; | 898 | time_t now; |
| 919 | struct tm *ltime; | 899 | struct tm *ltime; |
| @@ -929,9 +909,8 @@ mbx_delimit_begin (mbf) | |||
| 929 | return (OK); | 909 | return (OK); |
| 930 | } | 910 | } |
| 931 | 911 | ||
| 932 | int | 912 | static int |
| 933 | mbx_delimit_end (mbf) | 913 | mbx_delimit_end (FILE *mbf) |
| 934 | FILE *mbf; | ||
| 935 | { | 914 | { |
| 936 | if (putc ('\n', mbf) == EOF) | 915 | if (putc ('\n', mbf) == EOF) |
| 937 | return (NOTOK); | 916 | return (NOTOK); |