2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
26 * $TOG: POP2Server.C /main/6 1998/11/10 17:08:56 mgreess $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1993, 1995, 1995 Sun Microsystems, Inc. All rights reserved.
43 * Common Desktop Environment
45 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
46 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
47 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
48 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
49 * (c) Copyright 1995 Digital Equipment Corp.
50 * (c) Copyright 1995 Fujitsu Limited
51 * (c) Copyright 1995 Hitachi, Ltd.
54 * RESTRICTED RIGHTS LEGEND
56 *Use, duplication, or disclosure by the U.S. Government is subject to
57 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
58 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
59 *for non-DOD U.S. Government Departments and Agencies are as set forth in
60 *FAR 52.227-19(c)(1,2).
62 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
63 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
64 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
65 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
66 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
67 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
68 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
74 #include <DtMail/DtMailServer.hh>
75 #include <DtMail/IO.hh>
77 POP2Server::POP2Server(
79 DtMail::Session *session,
80 DtMail::MailBox *mailbox,
81 DtMailAppendCallback append_mailbox_cb,
82 void *append_mailbox_cb_data)
83 : DtMailServer(folder, session, mailbox,
84 append_mailbox_cb, append_mailbox_cb_data)
90 POP2Server::~POP2Server()
96 // Request nth message.
99 POP2Server::ptrans_retrieve_start(int msg, int *lenp)
104 ok = do_transaction("READ %d", msg);
105 if (DTME_NoError != ok) return ok;
108 ok = do_send("RETR");
113 // Apply for connection authorization.
116 POP2Server::ptrans_authorize(char*)
119 ok = do_transaction("HELO %s %s", _username, _password);
120 if (DTME_NoError != ok) return DTME_MailServerAccess_AuthorizationFailed;
125 // Get range of messages to be fetched.
128 POP2Server::ptrans_fldstate_read(int *countp, int *newp)
131 // We should have picked up a count of messages in the user's
132 // default inbox from the pop2_getauth() response.
134 if (_pound_arg == -1)
135 return DTME_MailServerAccess_Error;
137 // Maybe the user wanted a non-default folder.
142 ok = do_transaction("FOLD %s", _folder);
143 if (DTME_NoError != ok) return ok;
144 if (_pound_arg == -1) return DTME_MailServerAccess_Error;
147 *countp = _pound_arg;
154 // Capture the sizes of all messages.
157 POP2Server::ptrans_msgsizes(int countp, int *sizes)
159 memset((char*) sizes, 0, countp * sizeof(int));
164 // Is the given message old?
167 POP2Server::ptrans_msgisold(int)
173 // Parse POP2 command response.
176 POP2Server::ptrans_parse_response (char *argbuf)
179 char buf[DTMAS_POPBUFSIZE+1];
181 _pound_arg = _equal_arg = -1;
182 if (SockGets(buf, sizeof(buf), _sockfp))
184 if (buf[strlen(buf)-1] == '\n')
185 buf[strlen(buf)-1] = '\0';
186 if (buf[strlen(buf)-1] == '\r')
187 buf[strlen(buf)-1] = '\r';
190 _logger.logError(DTM_FALSE, "%s< %s", proto_name(), buf);
194 else if (buf[0] == '#')
196 _pound_arg = atoi(buf+1);
199 else if (buf[0] == '=')
201 _equal_arg = atoi(buf+1);
204 else if (buf[0] == '-')
206 _logger.logError(DTM_FALSE, "Protocol Error reading response");
207 ok = DTME_MailServerAccess_Error;
211 _logger.logError(DTM_FALSE, "Protocol Violation reading response");
212 ok = DTME_MailServerAccess_ProtocolViolation;
220 _logger.logError(DTM_FALSE, "Socket Error reading response");
221 ok = DTME_MailServerAccess_SocketIOError;
228 // retrieve messages using POP2.
231 POP2Server::retrieve_messages(DtMailEnv &error)
233 DtMailServer::retrieve_messages(error);
237 // Send acknowledgement for message data.
240 POP2Server::ptrans_retrieve_end(int)
242 if (_removeafterdelivery)
243 return do_transaction("ACKD");
245 return do_transaction("ACKS");