Mercurial > hg > xemacs-beta
comparison lib-src/pop.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 11cf20601dec |
children | bbff43aa5eb7 |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
90 #include <krb5/ext-proto.h> | 90 #include <krb5/ext-proto.h> |
91 #include <ctype.h> | 91 #include <ctype.h> |
92 #endif /* KRB5 */ | 92 #endif /* KRB5 */ |
93 #endif /* KERBEROS */ | 93 #endif /* KERBEROS */ |
94 | 94 |
95 extern char *getenv (/* char * */); | |
96 extern char *getlogin (/* void */); | |
97 extern char *getpass (/* char * */); | |
98 extern char *strerror (/* int */); | |
99 extern char *index (); | |
100 | |
101 #ifdef KERBEROS | 95 #ifdef KERBEROS |
102 #ifndef KRB5 | 96 #ifndef KRB5 |
103 extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *, | 97 extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *, |
104 u_long, MSG_DAT *, CREDENTIALS *, Key_schedule, | 98 u_long, MSG_DAT *, CREDENTIALS *, Key_schedule, |
105 struct sockaddr_in *, struct sockaddr_in *, | 99 struct sockaddr_in *, struct sockaddr_in *, |
112 #if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H) | 106 #if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H) |
113 extern int h_errno; | 107 extern int h_errno; |
114 #endif | 108 #endif |
115 #endif | 109 #endif |
116 | 110 |
117 static int socket_connection (/* char *, int */); | 111 static int socket_connection (char *, int); |
118 static char *getline (/* popserver */); | 112 static char *pop_getline (popserver); |
119 static int sendline (/* popserver, char * */); | 113 static int sendline (popserver, char *); |
120 static int fullwrite (/* int, char *, int */); | 114 static int fullwrite (int, char *, int); |
121 static int getok (/* popserver */); | 115 static int getok (popserver); |
122 #if 0 | 116 #if 0 |
123 static int gettermination (/* popserver */); | 117 static int gettermination (popserver); |
124 #endif | 118 #endif |
125 static void pop_trash (/* popserver */); | 119 static void pop_trash (popserver); |
126 static char *find_crlf (/* char * */); | 120 static char *find_crlf (char *); |
127 | 121 |
128 #define ERROR_MAX 80 /* a pretty arbitrary size */ | 122 #define ERROR_MAX 80 /* a pretty arbitrary size */ |
129 #define POP_PORT 110 | 123 #define POP_PORT 110 |
130 #define KPOP_PORT 1109 | 124 #define KPOP_PORT 1109 |
131 #if defined(WINDOWSNT) || defined(__CYGWIN32__) | 125 #if defined(WINDOWSNT) || defined(__CYGWIN32__) |
176 * non-null popserver will be returned. Otherwise, null will be | 170 * non-null popserver will be returned. Otherwise, null will be |
177 * returned, and the string variable pop_error will contain an | 171 * returned, and the string variable pop_error will contain an |
178 * explanation of the error. | 172 * explanation of the error. |
179 */ | 173 */ |
180 popserver | 174 popserver |
181 pop_open (host, username, password, flags) | 175 pop_open (char *host, char *username, char *password, int flags) |
182 char *host; | |
183 char *username; | |
184 char *password; | |
185 int flags; | |
186 { | 176 { |
187 int sock; | 177 int sock; |
188 popserver server; | 178 popserver server; |
189 | 179 |
190 /* Determine the user name */ | 180 /* Determine the user name */ |
346 * | 336 * |
347 * Side effects: On failure, may make further operations on the | 337 * Side effects: On failure, may make further operations on the |
348 * connection impossible. | 338 * connection impossible. |
349 */ | 339 */ |
350 int | 340 int |
351 pop_stat (server, count, size) | 341 pop_stat (popserver server, int *count, int *size) |
352 popserver server; | |
353 int *count; | |
354 int *size; | |
355 { | 342 { |
356 char *fromserver; | 343 char *fromserver; |
357 | 344 |
358 if (server->in_multi) | 345 if (server->in_multi) |
359 { | 346 { |
360 strcpy (pop_error, "In multi-line query in pop_stat"); | 347 strcpy (pop_error, "In multi-line query in pop_stat"); |
361 return (-1); | 348 return (-1); |
362 } | 349 } |
363 | 350 |
364 if (sendline (server, "STAT") || (! (fromserver = getline (server)))) | 351 if (sendline (server, "STAT") || (! (fromserver = pop_getline (server)))) |
365 return (-1); | 352 return (-1); |
366 | 353 |
367 if (strncmp (fromserver, "+OK ", 4)) | 354 if (strncmp (fromserver, "+OK ", 4)) |
368 { | 355 { |
369 if (0 == strncmp (fromserver, "-ERR", 4)) | 356 if (0 == strncmp (fromserver, "-ERR", 4)) |
379 return (-1); | 366 return (-1); |
380 } | 367 } |
381 | 368 |
382 *count = atoi (&fromserver[4]); | 369 *count = atoi (&fromserver[4]); |
383 | 370 |
384 fromserver = index (&fromserver[4], ' '); | 371 fromserver = strchr (&fromserver[4], ' '); |
385 if (! fromserver) | 372 if (! fromserver) |
386 { | 373 { |
387 strcpy (pop_error, | 374 strcpy (pop_error, |
388 "Badly formatted response from server in pop_stat"); | 375 "Badly formatted response from server in pop_stat"); |
389 pop_trash (server); | 376 pop_trash (server); |
413 * | 400 * |
414 * Side effects: On failure, may make further operations on the | 401 * Side effects: On failure, may make further operations on the |
415 * connection impossible. | 402 * connection impossible. |
416 */ | 403 */ |
417 int | 404 int |
418 pop_list (server, message, IDs, sizes) | 405 pop_list (popserver server, int message, int **IDs, int **sizes) |
419 popserver server; | |
420 int message; | |
421 int **IDs; | |
422 int **sizes; | |
423 { | 406 { |
424 int how_many, i; | 407 int how_many, i; |
425 char *fromserver; | 408 char *fromserver; |
426 | 409 |
427 if (server->in_multi) | 410 if (server->in_multi) |
455 { | 438 { |
456 free ((char *) *IDs); | 439 free ((char *) *IDs); |
457 free ((char *) *sizes); | 440 free ((char *) *sizes); |
458 return (-1); | 441 return (-1); |
459 } | 442 } |
460 if (! (fromserver = getline (server))) | 443 if (! (fromserver = pop_getline (server))) |
461 { | 444 { |
462 free ((char *) *IDs); | 445 free ((char *) *IDs); |
463 free ((char *) *sizes); | 446 free ((char *) *sizes); |
464 return (-1); | 447 return (-1); |
465 } | 448 } |
476 free ((char *) *IDs); | 459 free ((char *) *IDs); |
477 free ((char *) *sizes); | 460 free ((char *) *sizes); |
478 return (-1); | 461 return (-1); |
479 } | 462 } |
480 (*IDs)[0] = atoi (&fromserver[4]); | 463 (*IDs)[0] = atoi (&fromserver[4]); |
481 fromserver = index (&fromserver[4], ' '); | 464 fromserver = strchr (&fromserver[4], ' '); |
482 if (! fromserver) | 465 if (! fromserver) |
483 { | 466 { |
484 strcpy (pop_error, | 467 strcpy (pop_error, |
485 "Badly formatted response from server in pop_list"); | 468 "Badly formatted response from server in pop_list"); |
486 pop_trash (server); | 469 pop_trash (server); |
507 free ((char *) *IDs); | 490 free ((char *) *IDs); |
508 free ((char *) *sizes); | 491 free ((char *) *sizes); |
509 return (-1); | 492 return (-1); |
510 } | 493 } |
511 (*IDs)[i] = atoi (fromserver); | 494 (*IDs)[i] = atoi (fromserver); |
512 fromserver = index (fromserver, ' '); | 495 fromserver = strchr (fromserver, ' '); |
513 if (! fromserver) | 496 if (! fromserver) |
514 { | 497 { |
515 strcpy (pop_error, | 498 strcpy (pop_error, |
516 "Badly formatted response from server in pop_list"); | 499 "Badly formatted response from server in pop_list"); |
517 free ((char *) *IDs); | 500 free ((char *) *IDs); |
556 * null with pop_error set if not. | 539 * null with pop_error set if not. |
557 * | 540 * |
558 * Side effects: May kill connection on error. | 541 * Side effects: May kill connection on error. |
559 */ | 542 */ |
560 char * | 543 char * |
561 pop_retrieve (server, message, markfrom) | 544 pop_retrieve (popserver server, int message, int markfrom) |
562 popserver server; | |
563 int message; | |
564 int markfrom; | |
565 { | 545 { |
566 int *IDs, *sizes, bufsize, fromcount = 0, cp = 0; | 546 int *IDs, *sizes, bufsize, fromcount = 0, cp = 0; |
567 char *ptr, *fromserver; | 547 char *ptr, *fromserver; |
568 int ret; | 548 int ret; |
569 | 549 |
625 fromcount = 0; | 605 fromcount = 0; |
626 } | 606 } |
627 ptr[cp++] = '>'; | 607 ptr[cp++] = '>'; |
628 } | 608 } |
629 linesize = strlen (fromserver); | 609 linesize = strlen (fromserver); |
630 bcopy (fromserver, &ptr[cp], linesize); | 610 memcpy (&ptr[cp], fromserver, linesize); |
631 cp += linesize; | 611 cp += linesize; |
632 ptr[cp++] = '\n'; | 612 ptr[cp++] = '\n'; |
633 } | 613 } |
634 | 614 |
635 if (ret) | 615 if (ret) |
640 /* This function used to fall off the end, but that doesn't make any sense */ | 620 /* This function used to fall off the end, but that doesn't make any sense */ |
641 return (0); | 621 return (0); |
642 } | 622 } |
643 | 623 |
644 int | 624 int |
645 pop_retrieve_first (server, message, response) | 625 pop_retrieve_first (popserver server, int message, char **response) |
646 popserver server; | |
647 int message; | |
648 char **response; | |
649 { | 626 { |
650 sprintf (pop_error, "RETR %d", message); | 627 sprintf (pop_error, "RETR %d", message); |
651 return (pop_multi_first (server, pop_error, response)); | 628 return (pop_multi_first (server, pop_error, response)); |
652 } | 629 } |
653 | 630 |
654 int | 631 int |
655 pop_retrieve_next (server, line) | 632 pop_retrieve_next (popserver server, char **line) |
656 popserver server; | |
657 char **line; | |
658 { | 633 { |
659 return (pop_multi_next (server, line)); | 634 return (pop_multi_next (server, line)); |
660 } | 635 } |
661 | 636 |
662 int | 637 int |
663 pop_retrieve_flush (server) | 638 pop_retrieve_flush (popserver server) |
664 popserver server; | |
665 { | 639 { |
666 return (pop_multi_flush (server)); | 640 return (pop_multi_flush (server)); |
667 } | 641 } |
668 | 642 |
669 int | 643 int |
670 pop_top_first (server, message, lines, response) | 644 pop_top_first (popserver server, int message, int lines, char **response) |
671 popserver server; | |
672 int message, lines; | |
673 char **response; | |
674 { | 645 { |
675 sprintf (pop_error, "TOP %d %d", message, lines); | 646 sprintf (pop_error, "TOP %d %d", message, lines); |
676 return (pop_multi_first (server, pop_error, response)); | 647 return (pop_multi_first (server, pop_error, response)); |
677 } | 648 } |
678 | 649 |
679 int | 650 int |
680 pop_top_next (server, line) | 651 pop_top_next (popserver server, char **line) |
681 popserver server; | |
682 char **line; | |
683 { | 652 { |
684 return (pop_multi_next (server, line)); | 653 return (pop_multi_next (server, line)); |
685 } | 654 } |
686 | 655 |
687 int | 656 int |
688 pop_top_flush (server) | 657 pop_top_flush (popserver server) |
689 popserver server; | |
690 { | 658 { |
691 return (pop_multi_flush (server)); | 659 return (pop_multi_flush (server)); |
692 } | 660 } |
693 | 661 |
694 int | 662 int |
695 pop_multi_first (server, command, response) | 663 pop_multi_first (popserver server, char *command, char **response) |
696 popserver server; | |
697 char *command; | |
698 char **response; | |
699 { | 664 { |
700 if (server->in_multi) | 665 if (server->in_multi) |
701 { | 666 { |
702 strcpy (pop_error, | 667 strcpy (pop_error, |
703 "Already in multi-line query in pop_multi_first"); | 668 "Already in multi-line query in pop_multi_first"); |
704 return (-1); | 669 return (-1); |
705 } | 670 } |
706 | 671 |
707 if (sendline (server, command) || (! (*response = getline (server)))) | 672 if (sendline (server, command) || (! (*response = pop_getline (server)))) |
708 { | 673 { |
709 return (-1); | 674 return (-1); |
710 } | 675 } |
711 | 676 |
712 if (0 == strncmp (*response, "-ERR", 4)) | 677 if (0 == strncmp (*response, "-ERR", 4)) |
727 return (-1); | 692 return (-1); |
728 } | 693 } |
729 } | 694 } |
730 | 695 |
731 int | 696 int |
732 pop_multi_next (server, line) | 697 pop_multi_next (popserver server, char **line) |
733 popserver server; | |
734 char **line; | |
735 { | 698 { |
736 char *fromserver; | 699 char *fromserver; |
737 | 700 |
738 if (! server->in_multi) | 701 if (! server->in_multi) |
739 { | 702 { |
740 strcpy (pop_error, "Not in multi-line query in pop_multi_next"); | 703 strcpy (pop_error, "Not in multi-line query in pop_multi_next"); |
741 return (-1); | 704 return (-1); |
742 } | 705 } |
743 | 706 |
744 fromserver = getline (server); | 707 fromserver = pop_getline (server); |
745 if (! fromserver) | 708 if (! fromserver) |
746 { | 709 { |
747 return (-1); | 710 return (-1); |
748 } | 711 } |
749 | 712 |
767 return (0); | 730 return (0); |
768 } | 731 } |
769 } | 732 } |
770 | 733 |
771 int | 734 int |
772 pop_multi_flush (server) | 735 pop_multi_flush (popserver server) |
773 popserver server; | |
774 { | 736 { |
775 char *line; | 737 char *line; |
776 | 738 |
777 if (! server->in_multi) | 739 if (! server->in_multi) |
778 { | 740 { |
800 * | 762 * |
801 * Return value: 0 on success, non-zero with error in pop_error | 763 * Return value: 0 on success, non-zero with error in pop_error |
802 * otherwise. | 764 * otherwise. |
803 */ | 765 */ |
804 int | 766 int |
805 pop_delete (server, message) | 767 pop_delete (popserver server, int message) |
806 popserver server; | |
807 int message; | |
808 { | 768 { |
809 if (server->in_multi) | 769 if (server->in_multi) |
810 { | 770 { |
811 strcpy (pop_error, "In multi-line query in pop_delete"); | 771 strcpy (pop_error, "In multi-line query in pop_delete"); |
812 return (-1); | 772 return (-1); |
832 * otherwise. | 792 * otherwise. |
833 * | 793 * |
834 * Side effects: Closes connection on error. | 794 * Side effects: Closes connection on error. |
835 */ | 795 */ |
836 int | 796 int |
837 pop_noop (server) | 797 pop_noop (popserver server) |
838 popserver server; | |
839 { | 798 { |
840 if (server->in_multi) | 799 if (server->in_multi) |
841 { | 800 { |
842 strcpy (pop_error, "In multi-line query in pop_noop"); | 801 strcpy (pop_error, "In multi-line query in pop_noop"); |
843 return (-1); | 802 return (-1); |
862 * the error explained in pop_error. | 821 * the error explained in pop_error. |
863 * | 822 * |
864 * Side effects: Closes the connection on error. | 823 * Side effects: Closes the connection on error. |
865 */ | 824 */ |
866 int | 825 int |
867 pop_last (server) | 826 pop_last (popserver server) |
868 popserver server; | |
869 { | 827 { |
870 char *fromserver; | 828 char *fromserver; |
871 | 829 |
872 if (server->in_multi) | 830 if (server->in_multi) |
873 { | 831 { |
876 } | 834 } |
877 | 835 |
878 if (sendline (server, "LAST")) | 836 if (sendline (server, "LAST")) |
879 return (-1); | 837 return (-1); |
880 | 838 |
881 if (! (fromserver = getline (server))) | 839 if (! (fromserver = pop_getline (server))) |
882 return (-1); | 840 return (-1); |
883 | 841 |
884 if (! strncmp (fromserver, "-ERR", 4)) | 842 if (! strncmp (fromserver, "-ERR", 4)) |
885 { | 843 { |
886 strncpy (pop_error, fromserver, ERROR_MAX); | 844 strncpy (pop_error, fromserver, ERROR_MAX); |
910 * otherwise. | 868 * otherwise. |
911 * | 869 * |
912 * Side effects: Closes the connection on error. | 870 * Side effects: Closes the connection on error. |
913 */ | 871 */ |
914 int | 872 int |
915 pop_reset (server) | 873 pop_reset (popserver server) |
916 popserver server; | |
917 { | 874 { |
918 if (pop_retrieve_flush (server)) | 875 if (pop_retrieve_flush (server)) |
919 { | 876 { |
920 return (-1); | 877 return (-1); |
921 } | 878 } |
939 * | 896 * |
940 * Side Effects: The popserver passed in is unusable after this | 897 * Side Effects: The popserver passed in is unusable after this |
941 * function is called, even if an error occurs. | 898 * function is called, even if an error occurs. |
942 */ | 899 */ |
943 int | 900 int |
944 pop_quit (server) | 901 pop_quit (popserver server) |
945 popserver server; | |
946 { | 902 { |
947 int ret = 0; | 903 int ret = 0; |
948 | 904 |
949 if (server->file >= 0) | 905 if (server->file >= 0) |
950 { | 906 { |
985 * Return value: A file descriptor indicating the connection, or -1 | 941 * Return value: A file descriptor indicating the connection, or -1 |
986 * indicating failure, in which case an error has been copied | 942 * indicating failure, in which case an error has been copied |
987 * into pop_error. | 943 * into pop_error. |
988 */ | 944 */ |
989 static int | 945 static int |
990 socket_connection (host, flags) | 946 socket_connection (char *host, int flags) |
991 char *host; | |
992 int flags; | |
993 { | 947 { |
994 struct hostent *hostent; | 948 struct hostent *hostent; |
995 struct servent *servent; | 949 struct servent *servent; |
996 struct sockaddr_in addr; | 950 struct sockaddr_in addr; |
997 char found_port = 0; | 951 char found_port = 0; |
1036 strcpy (pop_error, "Could not determine POP server's address"); | 990 strcpy (pop_error, "Could not determine POP server's address"); |
1037 return (-1); | 991 return (-1); |
1038 } | 992 } |
1039 } while (! hostent); | 993 } while (! hostent); |
1040 | 994 |
1041 bzero ((char *) &addr, sizeof (addr)); | 995 memset (&addr, 0, sizeof (addr)); |
1042 addr.sin_family = AF_INET; | 996 addr.sin_family = AF_INET; |
1043 | 997 |
1044 #ifdef KERBEROS | 998 #ifdef KERBEROS |
1045 service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE; | 999 service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE; |
1046 #else | 1000 #else |
1088 | 1042 |
1089 } | 1043 } |
1090 | 1044 |
1091 while (*hostent->h_addr_list) | 1045 while (*hostent->h_addr_list) |
1092 { | 1046 { |
1093 bcopy (*hostent->h_addr_list, (char *) &addr.sin_addr, | 1047 memcpy (&addr.sin_addr, *hostent->h_addr_list, hostent->h_length); |
1094 hostent->h_length); | |
1095 if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr))) | 1048 if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr))) |
1096 break; | 1049 break; |
1097 hostent->h_addr_list++; | 1050 hostent->h_addr_list++; |
1098 } | 1051 } |
1099 | 1052 |
1205 | 1158 |
1206 return (sock); | 1159 return (sock); |
1207 } /* socket_connection */ | 1160 } /* socket_connection */ |
1208 | 1161 |
1209 /* | 1162 /* |
1210 * Function: getline | 1163 * Function: pop_getline |
1211 * | 1164 * |
1212 * Purpose: Get a line of text from the connection and return a | 1165 * Purpose: Get a line of text from the connection and return a |
1213 * pointer to it. The carriage return and linefeed at the end of | 1166 * pointer to it. The carriage return and linefeed at the end of |
1214 * the line are stripped, but periods at the beginnings of lines | 1167 * the line are stripped, but periods at the beginnings of lines |
1215 * are NOT dealt with in any special way. | 1168 * are NOT dealt with in any special way. |
1218 * server The server from which to get the line of text. | 1171 * server The server from which to get the line of text. |
1219 * | 1172 * |
1220 * Returns: A non-null pointer if successful, or a null pointer on any | 1173 * Returns: A non-null pointer if successful, or a null pointer on any |
1221 * error, with an error message copied into pop_error. | 1174 * error, with an error message copied into pop_error. |
1222 * | 1175 * |
1223 * Notes: The line returned is overwritten with each call to getline. | 1176 * Notes: The line returned is overwritten with each call to pop_getline. |
1224 * | 1177 * |
1225 * Side effects: Closes the connection on error. | 1178 * Side effects: Closes the connection on error. |
1226 */ | 1179 */ |
1227 static char * | 1180 static char * |
1228 getline (server) | 1181 pop_getline (popserver server) |
1229 popserver server; | |
1230 { | 1182 { |
1231 #define GETLINE_ERROR "Error reading from server: " | 1183 #define GETLINE_ERROR "Error reading from server: " |
1232 | 1184 |
1233 int ret; | 1185 int ret; |
1234 int search_offset = 0; | 1186 int search_offset = 0; |
1252 fprintf (stderr, "<<< %s\n", server->buffer + found); | 1204 fprintf (stderr, "<<< %s\n", server->buffer + found); |
1253 return (server->buffer + found); | 1205 return (server->buffer + found); |
1254 } | 1206 } |
1255 else | 1207 else |
1256 { | 1208 { |
1257 bcopy (server->buffer + server->buffer_index, | 1209 memcpy (server->buffer, |
1258 server->buffer, server->data); | 1210 server->buffer + server->buffer_index, |
1211 server->data); | |
1259 /* Record the fact that we've searched the data already in | 1212 /* Record the fact that we've searched the data already in |
1260 the buffer for a CRLF, so that when we search below, we | 1213 the buffer for a CRLF, so that when we search below, we |
1261 don't have to search the same data twice. There's a "- | 1214 don't have to search the same data twice. There's a "- |
1262 1" here to account for the fact that the last character | 1215 1" here to account for the fact that the last character |
1263 of the data we have may be the CR of a CRLF pair, of | 1216 of the data we have may be the CR of a CRLF pair, of |
1281 { | 1234 { |
1282 server->buffer_size += GETLINE_INCR; | 1235 server->buffer_size += GETLINE_INCR; |
1283 server->buffer = (char *)realloc (server->buffer, server->buffer_size); | 1236 server->buffer = (char *)realloc (server->buffer, server->buffer_size); |
1284 if (! server->buffer) | 1237 if (! server->buffer) |
1285 { | 1238 { |
1286 strcpy (pop_error, "Out of memory in getline"); | 1239 strcpy (pop_error, "Out of memory in pop_getline"); |
1287 pop_trash (server); | 1240 pop_trash (server); |
1288 return (0); | 1241 return (0); |
1289 } | 1242 } |
1290 } | 1243 } |
1291 ret = RECV (server->file, server->buffer + server->data, | 1244 ret = RECV (server->file, server->buffer + server->data, |
1298 pop_trash (server); | 1251 pop_trash (server); |
1299 return (0); | 1252 return (0); |
1300 } | 1253 } |
1301 else if (ret == 0) | 1254 else if (ret == 0) |
1302 { | 1255 { |
1303 strcpy (pop_error, "Unexpected EOF from server in getline"); | 1256 strcpy (pop_error, "Unexpected EOF from server in pop_getline"); |
1304 pop_trash (server); | 1257 pop_trash (server); |
1305 return (0); | 1258 return (0); |
1306 } | 1259 } |
1307 else | 1260 else |
1308 { | 1261 { |
1346 * an error will be copied into pop_error. | 1299 * an error will be copied into pop_error. |
1347 * | 1300 * |
1348 * Side effects: Closes the connection on error. | 1301 * Side effects: Closes the connection on error. |
1349 */ | 1302 */ |
1350 static int | 1303 static int |
1351 sendline (server, line) | 1304 sendline (popserver server, char *line) |
1352 popserver server; | |
1353 char *line; | |
1354 { | 1305 { |
1355 #define SENDLINE_ERROR "Error writing to POP server: " | 1306 #define SENDLINE_ERROR "Error writing to POP server: " |
1356 int ret; | 1307 int ret; |
1357 | 1308 |
1358 ret = fullwrite (server->file, line, strlen (line)); | 1309 ret = fullwrite (server->file, line, strlen (line)); |
1383 * has been written. | 1334 * has been written. |
1384 * | 1335 * |
1385 * Return value: Same as write. Pop_error is not set. | 1336 * Return value: Same as write. Pop_error is not set. |
1386 */ | 1337 */ |
1387 static int | 1338 static int |
1388 fullwrite (fd, buf, nbytes) | 1339 fullwrite (int fd, char *buf, int nbytes) |
1389 int fd; | |
1390 char *buf; | |
1391 int nbytes; | |
1392 { | 1340 { |
1393 char *cp; | 1341 char *cp; |
1394 int ret; | 1342 int ret; |
1395 | 1343 |
1396 cp = buf; | 1344 cp = buf; |
1416 * Returns: 0 for success, else for failure and puts error in pop_error. | 1364 * Returns: 0 for success, else for failure and puts error in pop_error. |
1417 * | 1365 * |
1418 * Side effects: On failure, may make the connection unusable. | 1366 * Side effects: On failure, may make the connection unusable. |
1419 */ | 1367 */ |
1420 static int | 1368 static int |
1421 getok (server) | 1369 getok (popserver server) |
1422 popserver server; | |
1423 { | 1370 { |
1424 char *fromline; | 1371 char *fromline; |
1425 | 1372 |
1426 if (! (fromline = getline (server))) | 1373 if (! (fromline = pop_getline (server))) |
1427 { | 1374 { |
1428 return (-1); | 1375 return (-1); |
1429 } | 1376 } |
1430 | 1377 |
1431 if (! strncmp (fromline, "+OK", 3)) | 1378 if (! strncmp (fromline, "+OK", 3)) |
1455 * Return value: 0 on success, non-zero with pop_error set on error. | 1402 * Return value: 0 on success, non-zero with pop_error set on error. |
1456 * | 1403 * |
1457 * Side effects: Closes the connection on error. | 1404 * Side effects: Closes the connection on error. |
1458 */ | 1405 */ |
1459 static int | 1406 static int |
1460 gettermination (server) | 1407 gettermination (popserver server) |
1461 popserver server; | |
1462 { | 1408 { |
1463 char *fromserver; | 1409 char *fromserver; |
1464 | 1410 |
1465 fromserver = getline (server); | 1411 fromserver = pop_getline (server); |
1466 if (! fromserver) | 1412 if (! fromserver) |
1467 return (-1); | 1413 return (-1); |
1468 | 1414 |
1469 if (strcmp (fromserver, ".")) | 1415 if (strcmp (fromserver, ".")) |
1470 { | 1416 { |
1489 * Side effects: The server is unusable after this function returns. | 1435 * Side effects: The server is unusable after this function returns. |
1490 * Changes made to the maildrop since the session was started (or | 1436 * Changes made to the maildrop since the session was started (or |
1491 * since the last pop_reset) may be lost. | 1437 * since the last pop_reset) may be lost. |
1492 */ | 1438 */ |
1493 void | 1439 void |
1494 pop_close (server) | 1440 pop_close (popserver server) |
1495 popserver server; | |
1496 { | 1441 { |
1497 pop_trash (server); | 1442 pop_trash (server); |
1498 free ((char *) server); | 1443 free ((char *) server); |
1499 | 1444 |
1500 return; | 1445 return; |
1506 * Purpose: Like pop_close or pop_quit, but doesn't deallocate the | 1451 * Purpose: Like pop_close or pop_quit, but doesn't deallocate the |
1507 * memory associated with the server. It is legal to call | 1452 * memory associated with the server. It is legal to call |
1508 * pop_close or pop_quit after this function has been called. | 1453 * pop_close or pop_quit after this function has been called. |
1509 */ | 1454 */ |
1510 static void | 1455 static void |
1511 pop_trash (server) | 1456 pop_trash (popserver server) |
1512 popserver server; | |
1513 { | 1457 { |
1514 if (server->file >= 0) | 1458 if (server->file >= 0) |
1515 { | 1459 { |
1516 /* avoid recursion; sendline can call pop_trash */ | 1460 /* avoid recursion; sendline can call pop_trash */ |
1517 if (server->trash_started) | 1461 if (server->trash_started) |
1538 | 1482 |
1539 /* Return a pointer to the first CRLF in IN_STRING, | 1483 /* Return a pointer to the first CRLF in IN_STRING, |
1540 or 0 if it does not contain one. */ | 1484 or 0 if it does not contain one. */ |
1541 | 1485 |
1542 static char * | 1486 static char * |
1543 find_crlf (in_string) | 1487 find_crlf (char *in_string) |
1544 char *in_string; | |
1545 { | 1488 { |
1546 while (1) | 1489 while (1) |
1547 { | 1490 { |
1548 if (! *in_string) | 1491 if (! *in_string) |
1549 return (0); | 1492 return (0); |