annotate lib-src/pop.c @ 259:11cf20601dec r20-5b28

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