annotate lib-src/pop.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 023b83f4e54b
children 04bc9d2f42c7
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (c) 1991, 1993, 1996 Free Software Foundation, Inc.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
3 Copyright (C) 2001 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Written by Jonathan Kamens, jik@security.ov.com.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 558
diff changeset
6 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 558
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 558
diff changeset
13 XEmacs is distributed in the hope that it will be useful,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 558
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #define NO_SHORTNAMES /* Tell config not to load remap.h */
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
25 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #define MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #ifdef MAIL_USE_POP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include <sys/types.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
33 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include <winsock.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #undef SOCKET_ERROR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #define RECV(s,buf,len,flags) recv(s,buf,len,flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #define SEND(s,buf,len,flags) send(s,buf,len,flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #define CLOSESOCKET(s) closesocket(s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #include <netinet/in.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include <sys/socket.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #define RECV(s,buf,len,flags) read(s,buf,len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #define SEND(s,buf,len,flags) write(s,buf,len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #define CLOSESOCKET(s) close(s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #include "pop.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #ifdef sun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #endif /* sun */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #ifdef HESIOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include <hesiod.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 * It really shouldn't be necessary to put this declaration here, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 * 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
57 * 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
58 * hesiod.h does.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 extern struct servent *hes_getservbyname (/* char *, char * */);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
63 #include "../src/syspwd.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
64 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #include <netdb.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
66 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
70 #ifdef HAVE_UNISTD_H
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #include <unistd.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
72 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #include <sys/stat.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
74 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #include <sys/file.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
76 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #include "../src/syswait.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
78 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #include "../src/systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #ifndef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #include <des.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #include <krb.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #else /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #include <krb5/krb5.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #include <krb5/ext-proto.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #endif /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #ifndef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *,
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
98 unsigned long, MSG_DAT *, CREDENTIALS *, Key_schedule,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 struct sockaddr_in *, struct sockaddr_in *,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 char * */);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 extern char *krb_realmofhost (/* char * */);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 #endif /* ! KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
105 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 extern int h_errno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 static int socket_connection (char *, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 static char *pop_getline (popserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 static int sendline (popserver, char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 static int fullwrite (int, char *, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 static int getok (popserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static int gettermination (popserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 static void pop_trash (popserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 static char *find_crlf (char *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #define ERROR_MAX 80 /* a pretty arbitrary size */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #define POP_PORT 110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 #define KPOP_PORT 1109
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
125 #if defined(WIN32_NATIVE) || defined(CYGWIN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #define POP_SERVICE "pop3" /* we don't want the POP2 port! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #define POP_SERVICE "pop"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #ifdef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #define KPOP_SERVICE "k5pop";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #define KPOP_SERVICE "kpop"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 char pop_error[ERROR_MAX];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 int pop_debug = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 #ifndef min
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 #define min(a,b) (((a) < (b)) ? (a) : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 #endif
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 * Function: pop_open (char *host, char *username, char *password,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 * int flags)
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 * Purpose: Establishes a connection with a post-office server, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 * completes the authorization portion of the session.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 * host The server host with which the connection should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 * established. Optional. If omitted, internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 * heuristics will be used to determine the server host,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 * if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 * username
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 * The username of the mail-drop to access. Optional.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 * If omitted, internal heuristics will be used to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 * determine the username, if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 * password
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 * The password to use for authorization. If omitted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 * internal heuristics will be used to determine the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 * password, if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 * flags A bit mask containing flags controlling certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 * functions of the routine. Valid flags are defined in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 * the file pop.h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 * Return value: Upon successful establishment of a connection, a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 * non-null popserver will be returned. Otherwise, null will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 * returned, and the string variable pop_error will contain an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 * explanation of the error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 popserver
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 pop_open (char *host, char *username, char *password, int flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 int sock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 popserver server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 /* Determine the user name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 if (! username)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 username = getenv ("USER");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 if (! (username && *username))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
186 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 username = getlogin ();
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 struct passwd *passwd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 passwd = getpwuid (getuid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 if (passwd && passwd->pw_name && *passwd->pw_name)
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 username = passwd->pw_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 else
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 strcpy (pop_error, "Could not determine username");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 }
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 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 strcpy (pop_error, "Could not determine username");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 * Determine the mail host.
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 if (! host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 host = getenv ("MAILHOST");
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #ifdef HESIOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 if ((! host) && (! (flags & POP_NO_HESIOD)))
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 struct hes_postoffice *office;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 office = hes_getmailhost (username);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 if (office && office->po_type && (! strcmp (office->po_type, "POP"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 && office->po_name && *office->po_name && office->po_host
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 && *office->po_host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 host = office->po_host;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 username = office->po_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 }
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 #ifdef MAILHOST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 if (! host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 host = MAILHOST;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 #endif
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 if (! host)
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 strcpy (pop_error, "Could not determine POP server");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 }
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 /* Determine the password */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 #define DONT_NEED_PASSWORD (! (flags & POP_NO_KERBEROS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 #define DONT_NEED_PASSWORD 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 if ((! password) && (! DONT_NEED_PASSWORD))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
255 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 if (! (flags & POP_NO_GETPASS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 password = getpass ("Enter POP password:");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 if (! password)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 strcpy (pop_error, "Could not determine POP password");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 }
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 if (password)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 flags |= POP_NO_KERBEROS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 password = username;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 sock = socket_connection (host, flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 if (sock == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 return (0);
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 server = (popserver) malloc (sizeof (struct _popserver));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 if (! server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 strcpy (pop_error, "Out of memory in pop_open");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 server->buffer = (char *) malloc (GETLINE_MIN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 if (! server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 strcpy (pop_error, "Out of memory in pop_open");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 free ((char *) server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 return (0);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 server->file = sock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 server->data = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 server->buffer_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 server->buffer_size = GETLINE_MIN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 server->in_multi = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 server->trash_started = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 if (getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
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 * I really shouldn't use the pop_error variable like this, but....
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 if (strlen (username) > ERROR_MAX - 6)
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 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 "Username too long; recompile pop.c with larger ERROR_MAX");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 sprintf (pop_error, "USER %s", username);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if (sendline (server, pop_error) || getok (server))
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 return (0);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 if (strlen (password) > ERROR_MAX - 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 pop_close (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 "Password too long; recompile pop.c with larger ERROR_MAX");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 sprintf (pop_error, "PASS %s", password);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 if (sendline (server, pop_error) || getok (server))
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 return (0);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 return (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 }
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 * Function: pop_stat
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 * Purpose: Issue the STAT command to the server and return (in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 * value parameters) the number of messages in the maildrop and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 * the total size of the maildrop.
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 * 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
342 * in failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 * Side effects: On failure, may make further operations on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 * connection impossible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 pop_stat (popserver server, int *count, int *size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 if (server->in_multi)
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 strcpy (pop_error, "In multi-line query in pop_stat");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 }
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 if (sendline (server, "STAT") || (! (fromserver = pop_getline (server))))
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 if (strncmp (fromserver, "+OK ", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 if (0 == strncmp (fromserver, "-ERR", 4))
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 strncpy (pop_error, fromserver, ERROR_MAX);
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 else
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 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 "Unexpected response from POP server in pop_stat");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 pop_trash (server);
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 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 *count = atoi (&fromserver[4]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 fromserver = strchr (&fromserver[4], ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 if (! fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 "Badly formatted response from server in pop_stat");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 *size = atoi (fromserver + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 return (0);
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
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 * Function: pop_list
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 * Purpose: Performs the POP "list" command and returns (in value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 * parameters) two malloc'd zero-terminated arrays -- one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 * message IDs, and a parallel one of sizes.
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 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 * server The pop connection to talk to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 * message The number of the one message about which to get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 * information, or 0 to get information about all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 * messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 * 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
406 * failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 * Side effects: On failure, may make further operations on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 * connection impossible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 pop_list (popserver server, int message, int **IDs, int **sizes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 int how_many, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 strcpy (pop_error, "In multi-line query in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 }
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 if (message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 how_many = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 else
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 int count, size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 if (pop_stat (server, &count, &size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 how_many = count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 *IDs = (int *) malloc ((how_many + 1) * sizeof (int));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 *sizes = (int *) malloc ((how_many + 1) * sizeof (int));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 if (! (*IDs && *sizes))
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 strcpy (pop_error, "Out of memory in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 }
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 if (message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 sprintf (pop_error, "LIST %d", message);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 if (sendline (server, pop_error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 return (-1);
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 if (! (fromserver = pop_getline (server)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 return (-1);
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 if (strncmp (fromserver, "+OK ", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 if (! strncmp (fromserver, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 strncpy (pop_error, fromserver, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 else
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 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 "Unexpected response from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 pop_trash (server);
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 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 return (-1);
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 (*IDs)[0] = atoi (&fromserver[4]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 fromserver = strchr (&fromserver[4], ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 if (! fromserver)
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 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 "Badly formatted response from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (*sizes)[0] = atoi (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (*IDs)[1] = (*sizes)[1] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 return (0);
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 if (pop_multi_first (server, "LIST", &fromserver))
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 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 return (-1);
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 for (i = 0; i < how_many; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 if (pop_multi_next (server, &fromserver))
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 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 return (-1);
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 (*IDs)[i] = atoi (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 fromserver = strchr (fromserver, ' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 if (! fromserver)
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 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 "Badly formatted response from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (*sizes)[i] = atoi (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 if (pop_multi_next (server, &fromserver))
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 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 return (-1);
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 else if (fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 "Too many response lines from server in pop_list");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 free ((char *) *IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 free ((char *) *sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (*IDs)[i] = (*sizes)[i] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 * Function: pop_retrieve
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 * Purpose: Retrieve a specified message from the maildrop.
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 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 * server The server to retrieve from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 * message The message number to retrieve.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 * markfrom
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 * If true, then mark the string "From " at the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 * of lines with '>'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 * Return value: A string pointing to the message, if successful, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 * null with pop_error set if not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 * Side effects: May kill connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 pop_retrieve (popserver server, int message, int markfrom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 int *IDs, *sizes, bufsize, fromcount = 0, cp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 char *ptr, *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 strcpy (pop_error, "In multi-line query in pop_retrieve");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 if (pop_list (server, message, &IDs, &sizes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 return (0);
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 if (pop_retrieve_first (server, message, &fromserver))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 return (0);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 * The "5" below is an arbitrary constant -- I assume that if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 * there are "From" lines in the text to be marked, there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 * 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
575 * allocate more space for them below.
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 bufsize = sizes[0] + (markfrom ? 5 : 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 ptr = (char *)malloc (bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 free ((char *) IDs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 free ((char *) sizes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 if (! ptr)
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 strcpy (pop_error, "Out of memory in pop_retrieve");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 pop_retrieve_flush (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 }
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 while (! (ret = pop_retrieve_next (server, &fromserver)))
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 int linesize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 if (! fromserver)
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 ptr[cp] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 return (ptr);
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 (markfrom && fromserver[0] == 'F' && fromserver[1] == 'r' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 fromserver[2] == 'o' && fromserver[3] == 'm' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 fromserver[4] == ' ')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 if (++fromcount == 5)
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 bufsize += 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 ptr = (char *)realloc (ptr, bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 if (! ptr)
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 strcpy (pop_error, "Out of memory in pop_retrieve");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 pop_retrieve_flush (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 fromcount = 0;
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 ptr[cp++] = '>';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 linesize = strlen (fromserver);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 memcpy (&ptr[cp], fromserver, linesize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 cp += linesize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 ptr[cp++] = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 if (ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 free (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 /* return (0); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 /* This function used to fall off the end, but that doesn't make any sense */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 return (0);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 pop_retrieve_next (popserver server, char **line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 return (pop_multi_next (server, line));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 pop_retrieve_flush (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 return (pop_multi_flush (server));
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 pop_top_first (popserver server, int message, int lines, char **response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 sprintf (pop_error, "TOP %d %d", message, lines);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 return (pop_multi_first (server, pop_error, response));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 }
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 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 pop_top_next (popserver server, char **line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 return (pop_multi_next (server, line));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 pop_top_flush (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 return (pop_multi_flush (server));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 pop_multi_first (popserver server, char *command, char **response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 "Already in multi-line query in pop_multi_first");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 return (-1);
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 if (sendline (server, command) || (! (*response = pop_getline (server))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 }
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 if (0 == strncmp (*response, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 strncpy (pop_error, *response, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 else if (0 == strncmp (*response, "+OK", 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 for (*response += 3; **response == ' '; (*response)++) /* empty */;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 server->in_multi = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 else
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 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 "Unexpected response from server in pop_multi_first");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 pop_multi_next (popserver server, char **line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 if (! server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 strcpy (pop_error, "Not in multi-line query in pop_multi_next");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 return (-1);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 fromserver = pop_getline (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 if (! fromserver)
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 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 if (fromserver[0] == '.')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 if (! fromserver[1])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 *line = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 server->in_multi = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 *line = fromserver + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 }
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 else
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 *line = fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 return (0);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 pop_multi_flush (popserver server)
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 char *line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 if (! server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 while (! pop_multi_next (server, &line))
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 if (! line)
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 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 }
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 return (-1);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 /* Function: pop_delete
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 * Purpose: Delete a specified message.
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 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 * server Server from which to delete the message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 * message Message to delete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 * Return value: 0 on success, non-zero with error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 * otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 pop_delete (popserver server, int message)
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 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 strcpy (pop_error, "In multi-line query in pop_delete");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 sprintf (pop_error, "DELE %d", message);
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 if (sendline (server, pop_error) || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 return (-1);
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 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 }
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 * Function: pop_noop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 * Purpose: Send a noop command to the server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 * Argument:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 * server The server to send to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 * Return value: 0 on success, non-zero with error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 * otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 * Side effects: Closes connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 pop_noop (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 if (server->in_multi)
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 strcpy (pop_error, "In multi-line query in pop_noop");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 if (sendline (server, "NOOP") || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 return (-1);
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 return (0);
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
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 * Function: pop_last
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 * Purpose: Find out the highest seen message from the server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 * server The server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 * Return value: If successful, the highest seen message, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 * greater than or equal to 0. Otherwise, a negative number with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 * the error explained in pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 * Side effects: Closes the connection on error.
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 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 pop_last (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 char *fromserver;
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 if (server->in_multi)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 strcpy (pop_error, "In multi-line query in pop_last");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
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 if (sendline (server, "LAST"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 if (! (fromserver = pop_getline (server)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 return (-1);
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 if (! strncmp (fromserver, "-ERR", 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 strncpy (pop_error, fromserver, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 else if (strncmp (fromserver, "+OK ", 4))
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 strcpy (pop_error, "Unexpected response from server in pop_last");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 return (atoi (&fromserver[4]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 * Function: pop_reset
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 * Purpose: Reset the server to its initial connect state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 * server The server.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 * Return value: 0 for success, non-0 with error in pop_error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 * otherwise.
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 * Side effects: Closes the connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 pop_reset (popserver server)
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 if (pop_retrieve_flush (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 {
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 if (sendline (server, "RSET") || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 return (-1);
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 return (0);
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 * Function: pop_quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 * Purpose: Quit the connection to the server,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 * server The server to quit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 * Return value: 0 for success, non-zero otherwise with error in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 * pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 * Side Effects: The popserver passed in is unusable after this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 * function is called, even if an error occurs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 pop_quit (popserver 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 int ret = 0;
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 if (server->file >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 if (pop_retrieve_flush (server))
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 ret = -1;
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 if (sendline (server, "QUIT") || getok (server))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 ret = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 }
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 CLOSESOCKET (server->file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 }
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 if (server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 free (server->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 free ((char *) server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 return (ret);
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
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
934 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 static int have_winsock = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 #endif
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 * Function: socket_connection
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 * Purpose: Opens the network connection with the mail host, without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 * doing any sort of I/O with it or anything.
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 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 * host The host to which to connect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 * flags Option flags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 * Return value: A file descriptor indicating the connection, or -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 * indicating failure, in which case an error has been copied
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 * into pop_error.
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 socket_connection (char *host, int flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 struct hostent *hostent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 struct servent *servent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 struct sockaddr_in addr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 char found_port = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 char *service;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 int sock;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 #ifdef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 krb5_error_code rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 krb5_ccache ccdef;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 krb5_principal client, server;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 krb5_error *err_ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 register char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 KTEXT ticket;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 MSG_DAT msg_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 CREDENTIALS cred;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 Key_schedule schedule;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 int rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 #endif /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 int try_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
979 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 WSADATA winsockData;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 if (WSAStartup (0x101, &winsockData) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 have_winsock = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 #endif
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 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 hostent = gethostbyname (host);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 try_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 if ((! hostent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 && ((h_errno != TRY_AGAIN) || (try_count == 5))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 strcpy (pop_error, "Could not determine POP server's address");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 } while (! hostent);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 memset (&addr, 0, sizeof (addr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 addr.sin_family = AF_INET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 service = POP_SERVICE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 #ifdef HESIOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 if (! (flags & POP_NO_HESIOD))
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 servent = hes_getservbyname (service, "tcp");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 if (servent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 addr.sin_port = servent->s_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 found_port = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 if (! found_port)
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 servent = getservbyname (service, "tcp");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 if (servent)
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 addr.sin_port = servent->s_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 }
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 addr.sin_port = htons ((flags & POP_NO_KERBEROS) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 POP_PORT : KPOP_PORT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 addr.sin_port = htons (POP_PORT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 #define SOCKET_ERROR "Could not create socket for POP connection: "
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 sock = socket (PF_INET, SOCK_STREAM, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 if (sock < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 strcpy (pop_error, SOCKET_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 ERROR_MAX - sizeof (SOCKET_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 while (*hostent->h_addr_list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 memcpy (&addr.sin_addr, *hostent->h_addr_list, hostent->h_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 hostent->h_addr_list++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 }
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 #define CONNECT_ERROR "Could not connect to POP server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 if (! *hostent->h_addr_list)
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 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 strcpy (pop_error, CONNECT_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 ERROR_MAX - sizeof (CONNECT_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 }
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 #ifdef KERBEROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 #define KRB_ERROR "Kerberos error connecting to POP server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 if (! (flags & POP_NO_KERBEROS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 #ifdef KRB5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 krb5_init_ets ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 if (rem = krb5_cc_default (&ccdef))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 krb5error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 strncat (pop_error, error_message (rem),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 ERROR_MAX - sizeof(KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 if (rem = krb5_cc_get_principal (ccdef, &client))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 goto krb5error;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 for (cp = hostent->h_name; *cp; cp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 if (isupper (*cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 *cp = tolower (*cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 if (rem = krb5_sname_to_principal (hostent->h_name, POP_SERVICE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 FALSE, &server))
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 goto krb5error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 rem = krb5_sendauth ((krb5_pointer) &sock, "KPOPV1.0", client, server,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 AP_OPTS_MUTUAL_REQUIRED,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 0, /* no checksum */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 0, /* no creds, use ccache instead */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 ccdef,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 0, /* don't need seq # */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 0, /* don't need subsession key */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 &err_ret,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 0); /* don't need reply */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 krb5_free_principal (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 if (rem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 if (err_ret && err_ret->text.length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 strncat (pop_error, error_message (rem),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 ERROR_MAX - sizeof (KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 strncat (pop_error, " [server says '",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 ERROR_MAX - strlen (pop_error) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 strncat (pop_error, err_ret->text.data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 min (ERROR_MAX - strlen (pop_error) - 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 err_ret->text.length));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 strncat (pop_error, "']",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 ERROR_MAX - strlen (pop_error) - 1);
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 else
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 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 strncat (pop_error, error_message (rem),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 ERROR_MAX - sizeof (KRB_ERROR));
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 if (err_ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 krb5_free_error (err_ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 #else /* ! KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 ticket = (KTEXT) malloc (sizeof (KTEXT_ST));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 rem = krb_sendauth (0L, sock, ticket, "pop", hostent->h_name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 (char *) krb_realmofhost (hostent->h_name),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 (unsigned long) 0, &msg_data, &cred, schedule,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (struct sockaddr_in *) 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (struct sockaddr_in *) 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 "KPOPV0.1");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 free ((char *) ticket);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 if (rem != KSUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 strcpy (pop_error, KRB_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 strncat (pop_error, krb_err_txt[rem],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 ERROR_MAX - sizeof (KRB_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 CLOSESOCKET (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 #endif /* KRB5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 #endif /* KERBEROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 return (sock);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 } /* socket_connection */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
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 * Function: pop_getline
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 * Purpose: Get a line of text from the connection and return a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 * pointer to it. The carriage return and linefeed at the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 * the line are stripped, but periods at the beginnings of lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 * are NOT dealt with in any special way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 * server The server from which to get the line of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 * Returns: A non-null pointer if successful, or a null pointer on any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 * error, with an error message copied into pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 * Notes: The line returned is overwritten with each call to pop_getline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 * Side effects: Closes the connection on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 pop_getline (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 #define GETLINE_ERROR "Error reading from server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 int search_offset = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 if (server->data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 char *cp = find_crlf (server->buffer + server->buffer_index);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 if (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 int found;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 int data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 found = server->buffer_index;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 data_used = (cp + 2) - server->buffer - found;
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 *cp = '\0'; /* terminate the string to be returned */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 server->data -= data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 server->buffer_index += data_used;
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 if (pop_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 fprintf (stderr, "<<< %s\n", server->buffer + found);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 return (server->buffer + found);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 memcpy (server->buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 server->buffer + server->buffer_index,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 server->data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 /* Record the fact that we've searched the data already in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 the buffer for a CRLF, so that when we search below, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 don't have to search the same data twice. There's a "-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 1" here to account for the fact that the last character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 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
1222 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
1223 to search it again when we read more data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 search_offset = server->data - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 server->buffer_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 server->buffer_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 }
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 while (1)
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 /* 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
1236 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
1237 that find_crlf knows where to stop when we call it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 if (server->data == server->buffer_size - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 server->buffer_size += GETLINE_INCR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 server->buffer = (char *)realloc (server->buffer, server->buffer_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 if (! server->buffer)
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 strcpy (pop_error, "Out of memory in pop_getline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 ret = RECV (server->file, server->buffer + server->data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 server->buffer_size - server->data - 1, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 if (ret < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 strcpy (pop_error, GETLINE_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 ERROR_MAX - sizeof (GETLINE_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 else if (ret == 0)
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 strcpy (pop_error, "Unexpected EOF from server in pop_getline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 server->data += ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 server->buffer[server->data] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 cp = find_crlf (server->buffer + search_offset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 if (cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 int data_used = (cp + 2) - server->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 *cp = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 server->data -= data_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 server->buffer_index = data_used;
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 if (pop_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 fprintf (stderr, "<<< %s\n", server->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 return (server->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 search_offset += ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 /* NOTREACHED */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 * Function: sendline
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 * 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
1294 * passed into this function should NOT have the carriage return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 * and linefeed on the end of it. Periods at beginnings of lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 * will NOT be treated specially by this function.
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 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 * server The server to which to send the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 * line The line of text to send.
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 * Return value: Upon successful completion, a value of 0 will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 * returned. Otherwise, a non-zero value will be returned, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 * an error will be copied into pop_error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 * Side effects: Closes the connection on error.
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 sendline (popserver server, char *line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 #define SENDLINE_ERROR "Error writing to POP server: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 int ret;
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 ret = fullwrite (server->file, line, strlen (line));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 if (ret >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 { /* 0 indicates that a blank line was written */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 ret = fullwrite (server->file, "\r\n", 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 if (ret < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 strcpy (pop_error, SENDLINE_ERROR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 strncat (pop_error, strerror (errno),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 ERROR_MAX - sizeof (SENDLINE_ERROR));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 return (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 }
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", line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 * Procedure: fullwrite
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 * Purpose: Just like write, but keeps trying until the entire string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 * has been written.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 * Return value: Same as write. Pop_error is not set.
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 fullwrite (int fd, char *buf, int nbytes)
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 char *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 cp = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 while ((ret = SEND (fd, cp, nbytes, 0)) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 cp += ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 nbytes -= ret;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 return (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 }
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 * Procedure getok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 * Purpose: Reads a line from the server. If the return indicator is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 * positive, return with a zero exit status. If not, return with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 * a negative exit status.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 * Arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 * server The server to read from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 * 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
1370 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 * Side effects: On failure, may make the connection unusable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 getok (popserver server)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 char *fromline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 if (! (fromline = pop_getline (server)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 if (! strncmp (fromline, "+OK", 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 else if (! strncmp (fromline, "-ERR", 4))
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 strncpy (pop_error, fromline, ERROR_MAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 pop_error[ERROR_MAX-1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 else
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 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 "Unexpected response from server; expecting +OK or -ERR");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 return (-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 }
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 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 * Function: gettermination
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 * Purpose: Gets the next line and verifies that it is a termination
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 * line (nothing but a dot).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 * 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
1408 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 * Side effects: Closes the connection on error.
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 gettermination (popserver server)
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 char *fromserver;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 fromserver = pop_getline (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 if (! fromserver)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 return (-1);
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 if (strcmp (fromserver, "."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 strcpy (pop_error,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 "Unexpected response from server in gettermination");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 return (-1);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 * Function pop_close
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 * Purpose: Close a pop connection, sending a "RSET" command to try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 * preserve any changes that were made and a "QUIT" command to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 * try to get the server to quit, but ignoring any responses that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 * are received.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 * Side effects: The server is unusable after this function returns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 * Changes made to the maildrop since the session was started (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 * since the last pop_reset) may be lost.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 pop_close (popserver server)
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 pop_trash (server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 free ((char *) server);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 return;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 * Function: pop_trash
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 * Purpose: Like pop_close or pop_quit, but doesn't deallocate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 * memory associated with the server. It is legal to call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 * pop_close or pop_quit after this function has been called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 pop_trash (popserver server)
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 if (server->file >= 0)
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 /* avoid recursion; sendline can call pop_trash */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 if (server->trash_started)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 server->trash_started = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 sendline (server, "RSET");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 sendline (server, "QUIT");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 CLOSESOCKET (server->file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 server->file = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 if (server->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 free (server->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 server->buffer = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 438
diff changeset
1482 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 if (have_winsock)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 WSACleanup ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 /* Return a pointer to the first CRLF in IN_STRING,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 or 0 if it does not contain one. */
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 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 find_crlf (char *in_string)
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 while (1)
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 if (! *in_string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 return (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 else if (*in_string == '\r')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 if (*++in_string == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 return (in_string - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 in_string++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 /* NOTREACHED */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 #endif /* MAIL_USE_POP */