comparison lib-src/movemail.c @ 31233:77ed917b12ee

(toplevel) [HAVE_STRING_H]: Include string.h. (toplevel) [HAVE_STRINGS_H]: Include strings.h.
author Dave Love <fx@gnu.org>
date Mon, 28 Aug 2000 18:56:15 +0000
parents 7ae519dba237
children b63fdc46cda2
comparison
equal deleted inserted replaced
31232:5213900983ed 31233:77ed917b12ee
59 #include <sys/types.h> 59 #include <sys/types.h>
60 #include <sys/stat.h> 60 #include <sys/stat.h>
61 #include <sys/file.h> 61 #include <sys/file.h>
62 #include <stdio.h> 62 #include <stdio.h>
63 #include <errno.h> 63 #include <errno.h>
64 #include <../src/syswait.h> 64 #ifdef HAVE_STRING_H
65 #include <string.h>
66 #endif
67
68 #ifdef HAVE_STRINGS_H
69 #include <strings.h>
70 #endif
71 #include "syswait.h"
65 #include <getopt.h> 72 #include <getopt.h>
73 #ifdef HAVE_FCNTL_H
74 #include <fcntl.h>
75 #endif
66 #ifdef MAIL_USE_POP 76 #ifdef MAIL_USE_POP
67 #include "pop.h" 77 #include "pop.h"
68 #endif 78 #endif
69 79
70 #ifdef MSDOS 80 #ifdef MSDOS
96 //#define DISABLE_DIRECT_ACCESS 106 //#define DISABLE_DIRECT_ACCESS
97 107
98 #include <fcntl.h> 108 #include <fcntl.h>
99 #endif /* WINDOWSNT */ 109 #endif /* WINDOWSNT */
100 110
101 #ifdef USG 111 #ifdef HAVE_FCNTL_H
102 #include <fcntl.h> 112 #include <fcntl.h>
103 #include <unistd.h> 113 #endif
104 #ifndef F_OK 114 #ifndef F_OK
105 #define F_OK 0 115 #define F_OK 0
106 #define X_OK 1 116 #define X_OK 1
107 #define W_OK 2 117 #define W_OK 2
108 #define R_OK 4 118 #define R_OK 4
109 #endif 119 #endif
110 #endif /* USG */
111 120
112 #ifdef HAVE_UNISTD_H 121 #ifdef HAVE_UNISTD_H
113 #include <unistd.h> 122 #include <unistd.h>
114 #endif 123 #endif
115 124
600 fatal (s1, s2) 609 fatal (s1, s2)
601 char *s1, *s2; 610 char *s1, *s2;
602 { 611 {
603 if (delete_lockname) 612 if (delete_lockname)
604 unlink (delete_lockname); 613 unlink (delete_lockname);
605 error (s1, s2); 614 error (s1, s2, 0);
606 exit (1); 615 exit (1);
607 } 616 }
608 617
609 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ 618 /* Print error message. `s1' is printf control string, `s2' and `s3'
619 are args for it or null. */
610 620
611 void 621 void
612 error (s1, s2, s3) 622 error (s1, s2, s3)
613 char *s1, *s2, *s3; 623 char *s1, *s2, *s3;
614 { 624 {
615 fprintf (stderr, "movemail: "); 625 fprintf (stderr, "movemail: ");
616 fprintf (stderr, s1, s2, s3); 626 if (s3)
627 fprintf (stderr, s1, s2, s3);
628 else if (s2)
629 fprintf (stderr, s1, s2);
630 else
631 fprintf (stderr, s1);
617 fprintf (stderr, "\n"); 632 fprintf (stderr, "\n");
618 } 633 }
619 634
620 void 635 void
621 pfatal_with_name (name) 636 pfatal_with_name (name)
699 * If the mailbox is in the form "po:username:hostname", then it is 714 * If the mailbox is in the form "po:username:hostname", then it is
700 * modified by this function -- the second colon is replaced by a 715 * modified by this function -- the second colon is replaced by a
701 * null. 716 * null.
702 */ 717 */
703 718
719 int
704 popmail (mailbox, outfile, preserve, password, reverse_order) 720 popmail (mailbox, outfile, preserve, password, reverse_order)
705 char *mailbox; 721 char *mailbox;
706 char *outfile; 722 char *outfile;
707 int preserve; 723 int preserve;
708 char *password; 724 char *password;
722 *hostname++ = '\0'; 738 *hostname++ = '\0';
723 739
724 server = pop_open (hostname, user, password, POP_NO_GETPASS); 740 server = pop_open (hostname, user, password, POP_NO_GETPASS);
725 if (! server) 741 if (! server)
726 { 742 {
727 error ("Error connecting to POP server: %s", pop_error); 743 error ("Error connecting to POP server: %s", pop_error, 0);
728 return (1); 744 return (1);
729 } 745 }
730 746
731 if (pop_stat (server, &nmsgs, &nbytes)) 747 if (pop_stat (server, &nmsgs, &nbytes))
732 { 748 {
733 error ("Error getting message count from POP server: %s", pop_error); 749 error ("Error getting message count from POP server: %s", pop_error, 0);
734 return (1); 750 return (1);
735 } 751 }
736 752
737 if (!nmsgs) 753 if (!nmsgs)
738 { 754 {
750 fchown (mbfi, getuid (), -1); 766 fchown (mbfi, getuid (), -1);
751 767
752 if ((mbf = fdopen (mbfi, "wb")) == NULL) 768 if ((mbf = fdopen (mbfi, "wb")) == NULL)
753 { 769 {
754 pop_close (server); 770 pop_close (server);
755 error ("Error in fdopen: %s", strerror (errno)); 771 error ("Error in fdopen: %s", strerror (errno), 0);
756 close (mbfi); 772 close (mbfi);
757 unlink (outfile); 773 unlink (outfile);
758 return (1); 774 return (1);
759 } 775 }
760 776
774 for (i = start; i * increment <= end * increment; i += increment) 790 for (i = start; i * increment <= end * increment; i += increment)
775 { 791 {
776 mbx_delimit_begin (mbf); 792 mbx_delimit_begin (mbf);
777 if (pop_retr (server, i, mbf) != OK) 793 if (pop_retr (server, i, mbf) != OK)
778 { 794 {
779 error (Errmsg); 795 error (Errmsg, 0, 0);
780 close (mbfi); 796 close (mbfi);
781 return (1); 797 return (1);
782 } 798 }
783 mbx_delimit_end (mbf); 799 mbx_delimit_end (mbf);
784 fflush (mbf); 800 fflush (mbf);
785 if (ferror (mbf)) 801 if (ferror (mbf))
786 { 802 {
787 error ("Error in fflush: %s", strerror (errno)); 803 error ("Error in fflush: %s", strerror (errno), 0);
788 pop_close (server); 804 pop_close (server);
789 close (mbfi); 805 close (mbfi);
790 return (1); 806 return (1);
791 } 807 }
792 } 808 }
805 } 821 }
806 #endif 822 #endif
807 823
808 if (close (mbfi) == -1) 824 if (close (mbfi) == -1)
809 { 825 {
810 error ("Error in close: %s", strerror (errno)); 826 error ("Error in close: %s", strerror (errno), 0);
811 return (1); 827 return (1);
812 } 828 }
813 829
814 if (! preserve) 830 if (! preserve)
815 for (i = 1; i <= nmsgs; i++) 831 for (i = 1; i <= nmsgs; i++)
816 { 832 {
817 if (pop_delete (server, i)) 833 if (pop_delete (server, i))
818 { 834 {
819 error ("Error from POP server: %s", pop_error); 835 error ("Error from POP server: %s", pop_error, 0);
820 pop_close (server); 836 pop_close (server);
821 return (1); 837 return (1);
822 } 838 }
823 } 839 }
824 840
825 if (pop_quit (server)) 841 if (pop_quit (server))
826 { 842 {
827 error ("Error from POP server: %s", pop_error); 843 error ("Error from POP server: %s", pop_error, 0);
828 return (1); 844 return (1);
829 } 845 }
830 846
831 return (0); 847 return (0);
832 } 848 }
915 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF) 931 if (fputs ("\f\n0, unseen,,\n", mbf) == EOF)
916 return (NOTOK); 932 return (NOTOK);
917 return (OK); 933 return (OK);
918 } 934 }
919 935
936 int
920 mbx_delimit_end (mbf) 937 mbx_delimit_end (mbf)
921 FILE *mbf; 938 FILE *mbf;
922 { 939 {
923 if (putc ('\037', mbf) == EOF) 940 if (putc ('\037', mbf) == EOF)
924 return (NOTOK); 941 return (NOTOK);