2
0

AUTOServer.C 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. *+SNOTICE
  25. *
  26. * $TOG: AUTOServer.C /main/6 1998/11/10 17:07:17 mgreess $
  27. *
  28. * RESTRICTED CONFIDENTIAL INFORMATION:
  29. *
  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
  36. * Sun's request.
  37. *
  38. * Copyright 1993, 1995, 1995 Sun Microsystems, Inc. All rights reserved.
  39. *
  40. *+ENOTICE
  41. */
  42. /*
  43. * Common Desktop Environment
  44. *
  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.
  52. *
  53. *
  54. * RESTRICTED RIGHTS LEGEND
  55. *
  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).
  61. *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
  62. *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
  63. *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
  64. *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
  65. *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
  66. *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
  67. *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
  68. */
  69. #include <stdio.h>
  70. #include <string.h>
  71. #include <ctype.h>
  72. #include <stdlib.h>
  73. #include <DtMail/DtMailServer.hh>
  74. AUTOServer::AUTOServer(
  75. char *folder,
  76. DtMail::Session *session,
  77. DtMail::MailBox *mailbox,
  78. DtMailAppendCallback append_mailbox_cb,
  79. void *append_mailbox_cb_data)
  80. : DtMailServer(folder, session, mailbox,
  81. append_mailbox_cb, append_mailbox_cb_data)
  82. {
  83. _server = NULL;
  84. }
  85. AUTOServer::~AUTOServer()
  86. {
  87. }
  88. //
  89. // Set delete flag for given message.
  90. //
  91. DTMailError_t
  92. AUTOServer::ptrans_delete(int number)
  93. {
  94. static char *pname = "AUTOServer::ptrans_delete";
  95. if (_server) return _server->ptrans_delete(number);
  96. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  97. return DTME_MailServerAccess_Error;
  98. }
  99. //
  100. // Apply for connection authorization
  101. //
  102. DTMailError_t
  103. AUTOServer::ptrans_authorize(char *buf)
  104. {
  105. static char *pname = "AUTOServer::ptrans_authorize";
  106. if (_server) return _server->ptrans_authorize(buf);
  107. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  108. return DTME_MailServerAccess_Error;
  109. }
  110. //
  111. // Expunge deleted messages
  112. //
  113. DTMailError_t
  114. AUTOServer::ptrans_fldstate_expunge()
  115. {
  116. static char *pname = "AUTOServer::ptrans_fldstate_expunge";
  117. if (_server) return _server->ptrans_fldstate_expunge();
  118. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  119. return DTME_MailServerAccess_Error;
  120. }
  121. //
  122. // Get range of messages to be fetched
  123. //
  124. DTMailError_t
  125. AUTOServer::ptrans_fldstate_read(int *countp, int *newp)
  126. {
  127. static char *pname = "AUTOServer::ptrans_fldstate_read";
  128. if (_server) return _server->ptrans_fldstate_read(countp, newp);
  129. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  130. return DTME_MailServerAccess_Error;
  131. }
  132. //
  133. // Capture the sizes of all messages.
  134. //
  135. DTMailError_t
  136. AUTOServer::ptrans_msgsizes(int count, int *sizes)
  137. {
  138. static char *pname = "AUTOServer::ptrans_msgsizes";
  139. if (_server) return _server->ptrans_msgsizes(count, sizes);
  140. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  141. return DTME_MailServerAccess_Error;
  142. }
  143. //
  144. // Is the given message old?
  145. //
  146. int
  147. AUTOServer::ptrans_msgisold(int num)
  148. {
  149. static char *pname = "AUTOServer::ptrans_msgisold";
  150. if (_server) return _server->ptrans_msgisold(num);
  151. return 0;
  152. }
  153. //
  154. // Quit the server
  155. //
  156. DTMailError_t
  157. AUTOServer::ptrans_quit()
  158. {
  159. static char *pname = "AUTOServer::ptrans_quit";
  160. if (_server) return _server->ptrans_quit();
  161. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  162. return DTME_MailServerAccess_Error;
  163. }
  164. //
  165. // request nth message
  166. //
  167. DTMailError_t
  168. AUTOServer::ptrans_retrieve_start(int number, int *lenp)
  169. {
  170. static char *pname = "AUTOServer::ptrans_retrieve_start";
  171. if (_server) return _server->ptrans_retrieve_start(number, lenp);
  172. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  173. return DTME_MailServerAccess_Error;
  174. }
  175. //
  176. // Parse command response
  177. //
  178. DTMailError_t
  179. AUTOServer::ptrans_parse_response(char *argbuf)
  180. {
  181. static char *pname = "AUTOServer::ptrans_parse_response";
  182. if (_server) return _server->ptrans_parse_response(argbuf);
  183. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  184. return DTME_MailServerAccess_Error;
  185. }
  186. //
  187. // Retrieve messages using IMAP Version 2bis or Version 4.
  188. //
  189. void
  190. AUTOServer::retrieve_messages(DtMailEnv &error)
  191. {
  192. if (NULL != _server)
  193. {
  194. _server->retrieve_messages(error);
  195. return;
  196. }
  197. //
  198. // First time through
  199. //
  200. for (int i=0; i<AUTO_NPROTOCOLS; i++)
  201. {
  202. if (NULL != _server)
  203. delete _server;
  204. switch (i)
  205. {
  206. case AUTO_POP3:
  207. _server = new POP3Server(
  208. _folder,
  209. _session,
  210. _mailbox,
  211. _append_mailbox_cb,
  212. _append_mailbox_cb_data);
  213. break;
  214. case AUTO_APOP:
  215. _server = new APOPServer(
  216. _folder,
  217. _session,
  218. _mailbox,
  219. _append_mailbox_cb,
  220. _append_mailbox_cb_data);
  221. break;
  222. case AUTO_IMAP:
  223. _server = new IMAPServer(
  224. _folder,
  225. _session,
  226. _mailbox,
  227. _append_mailbox_cb,
  228. _append_mailbox_cb_data);
  229. break;
  230. case AUTO_POP2:
  231. _server = new POP2Server(
  232. _folder,
  233. _session,
  234. _mailbox,
  235. _append_mailbox_cb,
  236. _append_mailbox_cb_data);
  237. break;
  238. }
  239. if (NULL != _server)
  240. {
  241. if (NULL != _password)
  242. _server->set_password(_password);
  243. _server->retrieve_messages(error);
  244. if (DTME_MailServerAccess_MissingPassword == (DTMailError_t) error)
  245. {
  246. delete _server;
  247. _server = NULL;
  248. return;
  249. }
  250. else if (error.isNotSet())
  251. return;
  252. }
  253. }
  254. }
  255. //
  256. // Discard tail of FETCH response after reading message text.
  257. //
  258. DTMailError_t
  259. AUTOServer::ptrans_retrieve_end(int number)
  260. {
  261. static char *pname = "AUTOServer::ptrans_retrieve_end";
  262. if (_server)
  263. return _server->ptrans_retrieve_end(number);
  264. _logger.logError(DTM_FALSE, "%s: NULL server\n", pname);
  265. return DTME_MailServerAccess_Error;
  266. }