annotate lib-src/pop.c @ 5402:308d34e9f07d

Changed bulk of GPLv2 or later files identified by script
author Mats Lidell <matsl@xemacs.org>
date Thu, 14 Oct 2010 17:15:20 +0200
parents bdfcf05f635b
children 7984e732829e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* pop.c: client routines for talking to a POP3-protocol post-office server
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
2 Copyright (C) 1991, 1993, 1996, 1997, 1999, 2002, 2003, 2004,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
3 2005, 2006 Free Software Foundation, Inc.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
4 Copyright (C) 2001 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 Written by Jonathan Kamens, jik@security.ov.com.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 558
diff changeset
7 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
9 XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
10 under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
11 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
12 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
17 for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3650
diff changeset
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
21
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
22 /* Synched up with: FSF 22.0.50. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #define NO_SHORTNAMES /* Tell config not to load remap.h */
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
26 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #define MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include <sys/types.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
34 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include <winsock.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #undef SOCKET_ERROR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #define RECV(s,buf,len,flags) recv(s,buf,len,flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #define SEND(s,buf,len,flags) send(s,buf,len,flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #define CLOSESOCKET(s) closesocket(s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include <netinet/in.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #include <sys/socket.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #define RECV(s,buf,len,flags) read(s,buf,len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #define SEND(s,buf,len,flags) write(s,buf,len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #define CLOSESOCKET(s) close(s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include "pop.h"
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
48 #include "compiler.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #ifdef sun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #endif /* sun */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #ifdef HESIOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #include <hesiod.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 * It really shouldn't be necessary to put this declaration here, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 * the version of hesiod.h that Athena has installed in release 7.2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 * doesn't declare this function; I don't know if the 7.3 version of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 * hesiod.h does.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 extern struct servent *hes_getservbyname (/* char *, char * */);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
65 #include "../src/syspwd.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
66 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <netdb.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
68 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
72 #ifdef HAVE_UNISTD_H
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #include <unistd.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
74 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #include <sys/stat.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
76 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #include <sys/file.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
78 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #include "../src/syswait.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
80 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #include "../src/systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #ifndef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #include <des.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #include <krb.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #else /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #include <krb5/krb5.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #include <krb5/ext-proto.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #endif /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #ifndef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *,
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
100 u_long, MSG_DAT *, CREDENTIALS *, Key_schedule,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 struct sockaddr_in *, struct sockaddr_in *,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 char * */);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 extern char *krb_realmofhost (/* char * */);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #endif /* ! KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
107 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 extern int h_errno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 static int socket_connection (char *, int);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
114 static int pop_getline (popserver, char **);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 static int sendline (popserver, char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 static int fullwrite (int, char *, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static int getok (popserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 static int gettermination (popserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 static void pop_trash (popserver);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
122 static char *find_crlf (char *, int);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
124 #define ERROR_MAX 160 /* a pretty arbitrary size, but needs
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
125 to be bigger than the original
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
126 value of 80 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 #define POP_PORT 110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #define KPOP_PORT 1109
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
129 #if defined(WIN32_NATIVE) || defined(CYGWIN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 #define POP_SERVICE "pop3" /* we don't want the POP2 port! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #define POP_SERVICE "pop"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 #ifdef KRB5
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
136 #define KPOP_SERVICE "k5pop"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 #define KPOP_SERVICE "kpop"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 char pop_error[ERROR_MAX];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 int pop_debug = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 #ifndef min
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 #define min(a,b) (((a) < (b)) ? (a) : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 * Function: pop_open (char *host, char *username, char *password,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 * int flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 * Purpose: Establishes a connection with a post-office server, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 * completes the authorization portion of the session.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 * host The server host with which the connection should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 * established. Optional. If omitted, internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 * heuristics will be used to determine the server host,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 * if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 * username
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 * The username of the mail-drop to access. Optional.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 * If omitted, internal heuristics will be used to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 * determine the username, if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 * password
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 * The password to use for authorization. If omitted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 * internal heuristics will be used to determine the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 * password, if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 * flags A bit mask containing flags controlling certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 * functions of the routine. Valid flags are defined in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 * the file pop.h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 * Return value: Upon successful establishment of a connection, a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 * non-null popserver will be returned. Otherwise, null will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 * returned, and the string variable pop_error will contain an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 * explanation of the error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 popserver
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 pop_open (char *host, char *username, char *password, int flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 int sock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 popserver server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 /* Determine the user name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 if (! username)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 username = getenv ("USER");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 if (! (username && *username))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
190 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 username = getlogin ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 if (! (username && *username))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 struct passwd *passwd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 passwd = getpwuid (getuid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 if (passwd && passwd->pw_name && *passwd->pw_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 username = passwd->pw_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 strcpy (pop_error, "Could not determine username");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 strcpy (pop_error, "Could not determine username");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 * Determine the mail host.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 if (! host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 host = getenv ("MAILHOST");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 #ifdef HESIOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 if ((! host) && (! (flags & POP_NO_HESIOD)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 struct hes_postoffice *office;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 office = hes_getmailhost (username);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 if (office && office->po_type && (! strcmp (office->po_type, "POP"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 && office->po_name && *office->po_name && office->po_host
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 && *office->po_host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 host = office->po_host;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 username = office->po_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 #ifdef MAILHOST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 if (! host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 host = MAILHOST;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 if (! host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 strcpy (pop_error, "Could not determine POP server");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 /* Determine the password */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 #define DONT_NEED_PASSWORD (! (flags & POP_NO_KERBEROS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 #define DONT_NEED_PASSWORD 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 if ((! password) && (! DONT_NEED_PASSWORD))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
259 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 if (! (flags & POP_NO_GETPASS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 password = getpass ("Enter POP password:");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 if (! password)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 strcpy (pop_error, "Could not determine POP password");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 if (password)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 flags |= POP_NO_KERBEROS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 password = username;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 sock = socket_connection (host, flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 if (sock == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 server = (popserver) malloc (sizeof (struct _popserver));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 if (! server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 strcpy (pop_error, "Out of memory in pop_open");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 server->buffer = (char *) malloc (GETLINE_MIN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 if (! server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 strcpy (pop_error, "Out of memory in pop_open");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 free ((char *) server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 server->file = sock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 server->data = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 server->buffer_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 server->buffer_size = GETLINE_MIN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 server->in_multi = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 server->trash_started = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 if (getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 * I really shouldn't use the pop_error variable like this, but....
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 if (strlen (username) > ERROR_MAX - 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 "Username too long; recompile pop.c with larger ERROR_MAX");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 sprintf (pop_error, "USER %s", username);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 if (sendline (server, pop_error) || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 if (strlen (password) > ERROR_MAX - 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 "Password too long; recompile pop.c with larger ERROR_MAX");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 sprintf (pop_error, "PASS %s", password);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 if (sendline (server, pop_error) || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 return (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 * Function: pop_stat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 * Purpose: Issue the STAT command to the server and return (in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 * value parameters) the number of messages in the maildrop and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 * the total size of the maildrop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 * Return value: 0 on success, or non-zero with an error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 * in failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 * Side effects: On failure, may make further operations on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 * connection impossible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 pop_stat (popserver server, int *count, int *size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 strcpy (pop_error, "In multi-line query in pop_stat");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
362 if (sendline (server, "STAT") || (pop_getline (server, &fromserver) < 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 if (strncmp (fromserver, "+OK ", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 if (0 == strncmp (fromserver, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 strncpy (pop_error, fromserver, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 "Unexpected response from POP server in pop_stat");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 *count = atoi (&fromserver[4]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 fromserver = strchr (&fromserver[4], ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 if (! fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 "Badly formatted response from server in pop_stat");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 *size = atoi (fromserver + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 * Function: pop_list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 * Purpose: Performs the POP "list" command and returns (in value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 * parameters) two malloc'd zero-terminated arrays -- one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 * message IDs, and a parallel one of sizes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 * server The pop connection to talk to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 * message The number of the one message about which to get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 * information, or 0 to get information about all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 * messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 * Return value: 0 on success, non-zero with error in pop_error on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 * failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 * Side effects: On failure, may make further operations on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 * connection impossible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 pop_list (popserver server, int message, int **IDs, int **sizes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 int how_many, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 strcpy (pop_error, "In multi-line query in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 if (message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 how_many = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 int count, size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 if (pop_stat (server, &count, &size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 how_many = count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 *IDs = (int *) malloc ((how_many + 1) * sizeof (int));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 *sizes = (int *) malloc ((how_many + 1) * sizeof (int));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 if (! (*IDs && *sizes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 strcpy (pop_error, "Out of memory in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 if (message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 sprintf (pop_error, "LIST %d", message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 if (sendline (server, pop_error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 }
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
454 if (pop_getline (server, &fromserver) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 if (strncmp (fromserver, "+OK ", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 if (! strncmp (fromserver, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 strncpy (pop_error, fromserver, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 "Unexpected response from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (*IDs)[0] = atoi (&fromserver[4]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 fromserver = strchr (&fromserver[4], ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 if (! fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 "Badly formatted response from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (*sizes)[0] = atoi (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (*IDs)[1] = (*sizes)[1] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 if (pop_multi_first (server, "LIST", &fromserver))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 for (i = 0; i < how_many; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
499 if (pop_multi_next (server, &fromserver) <= 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (*IDs)[i] = atoi (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 fromserver = strchr (fromserver, ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 if (! fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 "Badly formatted response from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (*sizes)[i] = atoi (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 }
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
518 if (pop_multi_next (server, &fromserver) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 else if (fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 "Too many response lines from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (*IDs)[i] = (*sizes)[i] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 * Function: pop_retrieve
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 * Purpose: Retrieve a specified message from the maildrop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 * server The server to retrieve from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 * message The message number to retrieve.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 * markfrom
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 * If true, then mark the string "From " at the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 * of lines with '>'.
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
548 * msg_buf Output parameter to which a buffer containing the
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
549 * message is assigned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 *
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
551 * Return value: The number of bytes in msg_buf, which may contain
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
552 * embedded nulls, not including its final null, or -1 on error
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
553 * with pop_error set.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 * Side effects: May kill connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 */
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
557 int
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
558 pop_retrieve (popserver server, int message, int markfrom, char **msg_buf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 int *IDs, *sizes, bufsize, fromcount = 0, cp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 char *ptr, *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 strcpy (pop_error, "In multi-line query in pop_retrieve");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 if (pop_list (server, message, &IDs, &sizes))
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
571 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 if (pop_retrieve_first (server, message, &fromserver))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
575 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 * The "5" below is an arbitrary constant -- I assume that if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 * there are "From" lines in the text to be marked, there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 * probably won't be more than 5 of them. If there are, I
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 * allocate more space for them below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 bufsize = sizes[0] + (markfrom ? 5 : 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ptr = (char *)malloc (bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 free ((char *) IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 free ((char *) sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 if (! ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 strcpy (pop_error, "Out of memory in pop_retrieve");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 pop_retrieve_flush (server);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
593 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
596 while ((ret = pop_retrieve_next (server, &fromserver)) >= 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 if (! fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 ptr[cp] = '\0';
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
601 *msg_buf = ptr;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
602 return (cp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 if (markfrom && fromserver[0] == 'F' && fromserver[1] == 'r' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 fromserver[2] == 'o' && fromserver[3] == 'm' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 fromserver[4] == ' ')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 if (++fromcount == 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 bufsize += 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 ptr = (char *)realloc (ptr, bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 if (! ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 strcpy (pop_error, "Out of memory in pop_retrieve");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 pop_retrieve_flush (server);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
616 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 fromcount = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 ptr[cp++] = '>';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 }
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
622 memcpy (&ptr[cp], fromserver, ret);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
623 cp += ret;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 ptr[cp++] = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
627 free (ptr);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
628 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 pop_retrieve_first (popserver server, int message, char **response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 sprintf (pop_error, "RETR %d", message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 return (pop_multi_first (server, pop_error, response));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
638 /*
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
639 Returns a negative number on error, 0 to indicate that the data has
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
640 all been read (i.e., the server has returned a "." termination
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
641 line), or a positive number indicating the number of bytes in the
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
642 returned buffer (which is null-terminated and may contain embedded
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
643 nulls, but the returned bytecount doesn't include the final null).
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
644 */
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
645
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 pop_retrieve_next (popserver server, char **line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 return (pop_multi_next (server, line));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 pop_retrieve_flush (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 return (pop_multi_flush (server));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 pop_top_first (popserver server, int message, int lines, char **response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 sprintf (pop_error, "TOP %d %d", message, lines);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 return (pop_multi_first (server, pop_error, response));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
665 /*
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
666 Returns a negative number on error, 0 to indicate that the data has
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
667 all been read (i.e., the server has returned a "." termination
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
668 line), or a positive number indicating the number of bytes in the
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
669 returned buffer (which is null-terminated and may contain embedded
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
670 nulls, but the returned bytecount doesn't include the final null).
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
671 */
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
672
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 pop_top_next (popserver server, char **line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 return (pop_multi_next (server, line));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 pop_top_flush (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 return (pop_multi_flush (server));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 pop_multi_first (popserver server, char *command, char **response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 "Already in multi-line query in pop_multi_first");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
695 if (sendline (server, command) || (pop_getline (server, response) < 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 if (0 == strncmp (*response, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 strncpy (pop_error, *response, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 else if (0 == strncmp (*response, "+OK", 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 for (*response += 3; **response == ' '; (*response)++) /* empty */;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 server->in_multi = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 "Unexpected response from server in pop_multi_first");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
719 /*
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
720 Read the next line of data from SERVER and place a pointer to it
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
721 into LINE. Return -1 on error, 0 if there are no more lines to read
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
722 (i.e., the server has returned a line containing only "."), or a
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
723 positive number indicating the number of bytes in the LINE buffer
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
724 (not including the final null). The data in that buffer may contain
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
725 embedded nulls, but does not contain the final CRLF. When returning
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
726 0, LINE is set to null. */
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
727
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 pop_multi_next (popserver server, char **line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 char *fromserver;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
732 int ret;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 if (! server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 strcpy (pop_error, "Not in multi-line query in pop_multi_next");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
740 if ((ret = pop_getline (server, &fromserver)) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 if (fromserver[0] == '.')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 if (! fromserver[1])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 *line = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 server->in_multi = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 *line = fromserver + 1;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
756 return (ret - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 *line = fromserver;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
762 return (ret);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 pop_multi_flush (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 char *line;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
770 int ret;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 if (! server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
777 while ((ret = pop_multi_next (server, &line)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
779 if (ret < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
781 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
785 return (0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 /* Function: pop_delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 * Purpose: Delete a specified message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 * server Server from which to delete the message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 * message Message to delete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 * Return value: 0 on success, non-zero with error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 * otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 pop_delete (popserver server, int message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 strcpy (pop_error, "In multi-line query in pop_delete");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 sprintf (pop_error, "DELE %d", message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 if (sendline (server, pop_error) || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 * Function: pop_noop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 * Purpose: Send a noop command to the server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 * Argument:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 * server The server to send to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 * Return value: 0 on success, non-zero with error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 * otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 * Side effects: Closes connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 pop_noop (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 strcpy (pop_error, "In multi-line query in pop_noop");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 if (sendline (server, "NOOP") || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 * Function: pop_last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 * Purpose: Find out the highest seen message from the server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 * server The server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 * Return value: If successful, the highest seen message, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 * greater than or equal to 0. Otherwise, a negative number with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 * the error explained in pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 * Side effects: Closes the connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 pop_last (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 strcpy (pop_error, "In multi-line query in pop_last");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 if (sendline (server, "LAST"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
872 if (pop_getline (server, &fromserver) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 if (! strncmp (fromserver, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 strncpy (pop_error, fromserver, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 else if (strncmp (fromserver, "+OK ", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 strcpy (pop_error, "Unexpected response from server in pop_last");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 return (atoi (&fromserver[4]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 * Function: pop_reset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 * Purpose: Reset the server to its initial connect state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 * server The server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 * Return value: 0 for success, non-0 with error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 * otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 * Side effects: Closes the connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 pop_reset (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 if (pop_retrieve_flush (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 if (sendline (server, "RSET") || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 * Function: pop_quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 * Purpose: Quit the connection to the server,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 * server The server to quit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 * Return value: 0 for success, non-zero otherwise with error in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 * pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 * Side Effects: The popserver passed in is unusable after this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 * function is called, even if an error occurs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 pop_quit (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 int ret = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 if (server->file >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 if (pop_retrieve_flush (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 ret = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 if (sendline (server, "QUIT") || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 ret = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 CLOSESOCKET (server->file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 if (server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 free (server->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 free ((char *) server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 return (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
960 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 static int have_winsock = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 * Function: socket_connection
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 * Purpose: Opens the network connection with the mail host, without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 * doing any sort of I/O with it or anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 * host The host to which to connect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 * flags Option flags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 * Return value: A file descriptor indicating the connection, or -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 * indicating failure, in which case an error has been copied
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 * into pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 static int
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
979 socket_connection (char *host,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
980 #if defined (KERBEROS) || defined (HESIOD)
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
981 int flags
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
982 #else
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
983 int UNUSED (flags)
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
984 #endif
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 771
diff changeset
985 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 struct hostent *hostent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 struct servent *servent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 struct sockaddr_in addr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 char found_port = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 char *service;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 int sock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 #ifdef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 krb5_error_code rem;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
996 krb5_context kcontext = 0;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
997 krb5_auth_context auth_context = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 krb5_ccache ccdef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 krb5_principal client, server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 krb5_error *err_ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 KTEXT ticket;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 MSG_DAT msg_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 CREDENTIALS cred;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 Key_schedule schedule;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 int rem;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1008 char *realhost;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 #endif /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 int try_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
1014 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 WSADATA winsockData;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 if (WSAStartup (0x101, &winsockData) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 have_winsock = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 memset (&addr, 0, sizeof (addr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 addr.sin_family = AF_INET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 service = POP_SERVICE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 #ifdef HESIOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 if (! (flags & POP_NO_HESIOD))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 servent = hes_getservbyname (service, "tcp");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 if (servent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 addr.sin_port = servent->s_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 found_port = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 if (! found_port)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 servent = getservbyname (service, "tcp");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 if (servent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 addr.sin_port = servent->s_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 addr.sin_port = htons ((flags & POP_NO_KERBEROS) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 POP_PORT : KPOP_PORT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 addr.sin_port = htons (POP_PORT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1060 #define POP_SOCKET_ERROR "Could not create socket for POP connection: "
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 sock = socket (PF_INET, SOCK_STREAM, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 if (sock < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1065 strcpy (pop_error, POP_SOCKET_ERROR);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 strncat (pop_error, strerror (errno),
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1067 ERROR_MAX - sizeof (POP_SOCKET_ERROR));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1072 do
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1073 {
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1074 hostent = gethostbyname (host);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1075 try_count++;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1076 if ((! hostent) && ((h_errno != TRY_AGAIN) || (try_count == 5)))
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1077 {
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1078 strcpy (pop_error, "Could not determine POP server's address");
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1079 return (-1);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1080 }
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1081 } while (! hostent);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1082
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 while (*hostent->h_addr_list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 memcpy (&addr.sin_addr, *hostent->h_addr_list, hostent->h_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 hostent->h_addr_list++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 #define CONNECT_ERROR "Could not connect to POP server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 if (! *hostent->h_addr_list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 strcpy (pop_error, CONNECT_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 ERROR_MAX - sizeof (CONNECT_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 #define KRB_ERROR "Kerberos error connecting to POP server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 if (! (flags & POP_NO_KERBEROS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 #ifdef KRB5
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1108 if ((rem = krb5_init_context (&kcontext)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 krb5error:
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1111 if (auth_context)
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1112 krb5_auth_con_free (kcontext, auth_context);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1113 if (kcontext)
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1114 krb5_free_context (kcontext);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 strncat (pop_error, error_message (rem),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 ERROR_MAX - sizeof(KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1122 if ((rem = krb5_auth_con_init (kcontext, &auth_context)))
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1123 goto krb5error;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1124
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1125 if (rem = krb5_cc_default (kcontext, &ccdef))
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1126 goto krb5error;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1127
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1128 if (rem = krb5_cc_get_principal (kcontext, ccdef, &client))
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1129 goto krb5error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 for (cp = hostent->h_name; *cp; cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 if (isupper (*cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 *cp = tolower (*cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1139 if (rem = krb5_sname_to_principal (kcontext, hostent->h_name,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1140 POP_SERVICE, FALSE, &server))
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1141 goto krb5error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1143 rem = krb5_sendauth (kcontext, &auth_context,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1144 (krb5_pointer) &sock, "KPOPV1.0", client, server,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 AP_OPTS_MUTUAL_REQUIRED,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 0, /* no checksum */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 0, /* no creds, use ccache instead */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 ccdef,
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1149 &err_ret,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 0, /* don't need subsession key */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 0); /* don't need reply */
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1152 krb5_free_principal (kcontext, server);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 if (rem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 if (err_ret && err_ret->text.length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 strncat (pop_error, error_message (rem),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 ERROR_MAX - sizeof (KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 strncat (pop_error, " [server says '",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 ERROR_MAX - strlen (pop_error) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 strncat (pop_error, err_ret->text.data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 min (ERROR_MAX - strlen (pop_error) - 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 err_ret->text.length));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 strncat (pop_error, "']",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 ERROR_MAX - strlen (pop_error) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 strncat (pop_error, error_message (rem),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 ERROR_MAX - sizeof (KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 if (err_ret)
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1175 krb5_free_error (kcontext, err_ret);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1176 krb5_auth_con_free (kcontext, auth_context);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1177 krb5_free_context (kcontext);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 #else /* ! KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 ticket = (KTEXT) malloc (sizeof (KTEXT_ST));
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1184 rem = krb_sendauth (0L, sock, ticket, "pop", realhost,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1185 (char *) krb_realmofhost (realhost),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (unsigned long) 0, &msg_data, &cred, schedule,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (struct sockaddr_in *) 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (struct sockaddr_in *) 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 "KPOPV0.1");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 free ((char *) ticket);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1191 free (realhost);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 if (rem != KSUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 strncat (pop_error, krb_err_txt[rem],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 ERROR_MAX - sizeof (KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 #endif /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 return (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 } /* socket_connection */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 * Function: pop_getline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 * Purpose: Get a line of text from the connection and return a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 * pointer to it. The carriage return and linefeed at the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 * the line are stripped, but periods at the beginnings of lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 * are NOT dealt with in any special way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 * server The server from which to get the line of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 *
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1218 * Returns: The number of characters in the line, which is returned in
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1219 * LINE, not including the final null. A return value of 0
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1220 * indicates a blank line. A negative return value indicates an
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1221 * error (in which case the contents of LINE are undefined. In
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1222 * case of error, an error message is copied into pop_error.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 * Notes: The line returned is overwritten with each call to pop_getline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 * Side effects: Closes the connection on error.
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1227 *
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1228 * THE RETURNED LINE MAY CONTAIN EMBEDDED NULLS!
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 */
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1230 static int
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1231 pop_getline (popserver server, char **line)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 #define GETLINE_ERROR "Error reading from server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 int search_offset = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 if (server->data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1240 char *cp = find_crlf (server->buffer + server->buffer_index,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1241 server->data);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 if (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 int found;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 int data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 found = server->buffer_index;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 data_used = (cp + 2) - server->buffer - found;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 *cp = '\0'; /* terminate the string to be returned */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 server->data -= data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 server->buffer_index += data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 if (pop_debug)
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1255 /* Embedded nulls will truncate this output prematurely,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1256 but that's OK because it's just for debugging anyway. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 fprintf (stderr, "<<< %s\n", server->buffer + found);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1258 *line = server->buffer + found;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1259 return (data_used - 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 memcpy (server->buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 server->buffer + server->buffer_index,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 server->data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 /* Record the fact that we've searched the data already in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 the buffer for a CRLF, so that when we search below, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 don't have to search the same data twice. There's a "-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 1" here to account for the fact that the last character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 of the data we have may be the CR of a CRLF pair, of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 which we haven't read the second half yet, so we may have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 to search it again when we read more data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 search_offset = server->data - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 server->buffer_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 server->buffer_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 /* There's a "- 1" here to leave room for the null that we put
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 at the end of the read data below. We put the null there so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 that find_crlf knows where to stop when we call it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 if (server->data == server->buffer_size - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 server->buffer_size += GETLINE_INCR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 server->buffer = (char *)realloc (server->buffer, server->buffer_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 if (! server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 strcpy (pop_error, "Out of memory in pop_getline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 pop_trash (server);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1295 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 ret = RECV (server->file, server->buffer + server->data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 server->buffer_size - server->data - 1, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 if (ret < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 strcpy (pop_error, GETLINE_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 ERROR_MAX - sizeof (GETLINE_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 pop_trash (server);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1306 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 else if (ret == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 strcpy (pop_error, "Unexpected EOF from server in pop_getline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 pop_trash (server);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1312 return (-1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 server->data += ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 server->buffer[server->data] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1320 cp = find_crlf (server->buffer + search_offset,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1321 server->data - search_offset);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 if (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 int data_used = (cp + 2) - server->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 *cp = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 server->data -= data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 server->buffer_index = data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 if (pop_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 fprintf (stderr, "<<< %s\n", server->buffer);
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1331 *line = server->buffer;
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1332 return (data_used - 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 }
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1334 /* As above, the "- 1" here is to account for the fact that
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1335 we may have read a CR without its accompanying LF. */
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1336 search_offset += ret - 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 /* NOTREACHED */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 * Function: sendline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 * Purpose: Sends a line of text to the POP server. The line of text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 * passed into this function should NOT have the carriage return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 * and linefeed on the end of it. Periods at beginnings of lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 * will NOT be treated specially by this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 * server The server to which to send the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 * line The line of text to send.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 * Return value: Upon successful completion, a value of 0 will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 * returned. Otherwise, a non-zero value will be returned, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 * an error will be copied into pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 * Side effects: Closes the connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 sendline (popserver server, char *line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 #define SENDLINE_ERROR "Error writing to POP server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 int ret;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1366 char *buf;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1368 /* Combine the string and the CR-LF into one buffer. Otherwise, two
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1369 reasonable network stack optimizations, Nagle's algorithm and
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1370 delayed acks, combine to delay us a fraction of a second on every
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1371 message we send. (Movemail writes line without \r\n, client
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1372 kernel sends packet, server kernel delays the ack to see if it
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1373 can combine it with data, movemail writes \r\n, client kernel
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1374 waits because it has unacked data already in its outgoing queue,
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1375 client kernel eventually times out and sends.)
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1376
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1377 This can be something like 0.2s per command, which can add up
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1378 over a few dozen messages, and is a big chunk of the time we
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1379 spend fetching mail from a server close by. */
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1380 buf = alloca (strlen (line) + 3);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1381 strcpy (buf, line);
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1382 strcat (buf, "\r\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 ret = fullwrite (server->file, line, strlen (line));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 if (ret < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 strcpy (pop_error, SENDLINE_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 ERROR_MAX - sizeof (SENDLINE_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 return (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 if (pop_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 fprintf (stderr, ">>> %s\n", line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 * Procedure: fullwrite
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 * Purpose: Just like write, but keeps trying until the entire string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 * has been written.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 * Return value: Same as write. Pop_error is not set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 fullwrite (int fd, char *buf, int nbytes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 char *cp;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1412 int ret = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 cp = buf;
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1415 while (nbytes && ((ret = SEND (fd, cp, nbytes, 0)) > 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 cp += ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 nbytes -= ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 return (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 * Procedure getok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 * Purpose: Reads a line from the server. If the return indicator is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 * positive, return with a zero exit status. If not, return with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 * a negative exit status.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 * server The server to read from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 * Returns: 0 for success, else for failure and puts error in pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 * Side effects: On failure, may make the connection unusable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 getok (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 char *fromline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1443 if (pop_getline (server, &fromline) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 if (! strncmp (fromline, "+OK", 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 else if (! strncmp (fromline, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 strncpy (pop_error, fromline, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 pop_error[ERROR_MAX-1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 "Unexpected response from server; expecting +OK or -ERR");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 * Function: gettermination
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 * Purpose: Gets the next line and verifies that it is a termination
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 * line (nothing but a dot).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 * Return value: 0 on success, non-zero with pop_error set on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 * Side effects: Closes the connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 gettermination (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1481 if (pop_getline (server, &fromserver) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 if (strcmp (fromserver, "."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 "Unexpected response from server in gettermination");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 * Function pop_close
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 * Purpose: Close a pop connection, sending a "RSET" command to try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 * preserve any changes that were made and a "QUIT" command to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 * try to get the server to quit, but ignoring any responses that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 * are received.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 * Side effects: The server is unusable after this function returns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 * Changes made to the maildrop since the session was started (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 * since the last pop_reset) may be lost.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 pop_close (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 free ((char *) server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 * Function: pop_trash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 * Purpose: Like pop_close or pop_quit, but doesn't deallocate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 * memory associated with the server. It is legal to call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 * pop_close or pop_quit after this function has been called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 pop_trash (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 if (server->file >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 /* avoid recursion; sendline can call pop_trash */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 if (server->trash_started)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 server->trash_started = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 sendline (server, "RSET");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 sendline (server, "QUIT");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 CLOSESOCKET (server->file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 server->file = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 if (server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 free (server->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 server->buffer = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
1546 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 if (have_winsock)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 WSACleanup ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1552 /* Return a pointer to the first CRLF in IN_STRING, which can contain
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1553 embedded nulls and has LEN characters in it not including the final
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1554 null, or 0 if it does not contain one. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 static char *
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1557 find_crlf (char *in_string, int len)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1559 while (len--)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 {
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1561 if (*in_string == '\r')
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 if (*++in_string == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 return (in_string - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 in_string++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 }
3650
bdfcf05f635b [xemacs-hg @ 2006-11-01 20:55:09 by adrian]
adrian
parents: 2286
diff changeset
1569 return (0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 #endif /* MAIL_USE_POP */