aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/movemail.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src/movemail.c')
-rw-r--r--lib-src/movemail.c111
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
143char *strerror (); 146#ifndef HAVE_STRERROR
144#ifdef HAVE_INDEX 147char *strerror (int);
145extern char *index __P ((const char *, int));
146#endif
147#ifdef HAVE_RINDEX
148extern char *rindex __P((const char *, int));
149#endif 148#endif
150 149
151void fatal (); 150static void fatal (char *s1, char *s2, char *s3);
152void error (); 151static void error (char *s1, char *s2, char *s3);
153void pfatal_with_name (); 152static void pfatal_with_name (char *name);
154void pfatal_and_delete (); 153static void pfatal_and_delete (char *name);
155char *concat (); 154static char *concat (char *s1, char *s2, char *s3);
156long *xmalloc (); 155static long *xmalloc (unsigned int size);
157int popmail (); 156#ifdef MAIL_USE_POP
158int pop_retr (); 157static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order);
159int mbx_write (); 158static int pop_retr (popserver server, int msgno, FILE *arg);
160int mbx_delimit_begin (); 159static int mbx_write (char *line, int len, FILE *mbf);
161int mbx_delimit_end (); 160static int mbx_delimit_begin (FILE *mbf);
161static 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. */
164char *delete_lockname; 165char *delete_lockname;
165 166
166int 167int
167main (argc, argv) 168main (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
592void 591static void
593fatal (s1, s2, s3) 592fatal (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
605void 603static void
606error (s1, s2, s3) 604error (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
619void 616static void
620pfatal_with_name (name) 617pfatal_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
626void 622static void
627pfatal_and_delete (name) 623pfatal_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
637char * 632static char *
638concat (s1, s2, s3) 633concat (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
654long * 648static long *
655xmalloc (size) 649xmalloc (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
705int 698static int
706popmail (mailbox, outfile, preserve, password, reverse_order) 699popmail (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
836int 824static int
837pop_retr (server, msgno, arg) 825pop_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
887int 871static int
888mbx_write (line, len, mbf) 872mbx_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
914int 895static int
915mbx_delimit_begin (mbf) 896mbx_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
932int 912static int
933mbx_delimit_end (mbf) 913mbx_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);