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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: DmxMailbox.C /main/3 1996/04/21 19:55:45 drk $ */
30 * RESTRICTED CONFIDENTIAL INFORMATION:
32 * The information in this document is subject to special
33 * restrictions in a confidential disclosure agreement between
34 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
35 * document outside HP, IBM, Sun, USL, SCO, or Univel without
36 * Sun's specific written approval. This document and all copies
37 * and derivative works thereof must be returned or destroyed at
40 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
45 * Common Desktop Environment
47 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
48 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
49 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
50 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
51 * (c) Copyright 1995 Digital Equipment Corp.
52 * (c) Copyright 1995 Fujitsu Limited
53 * (c) Copyright 1995 Hitachi, Ltd.
56 * RESTRICTED RIGHTS LEGEND
58 *Use, duplication, or disclosure by the U.S. Government is subject to
59 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
60 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
61 *for non-DOD U.S. Government Departments and Agencies are as set forth in
62 *FAR 52.227-19(c)(1,2).
64 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
65 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
66 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
67 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
68 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
69 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
70 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
75 #include "MemUtils.hh"
78 const int DmxMailbox::_firstIndex = 1;
80 DmxMailbox::DmxMailbox (char *filename)
84 _fileName = strdup_n(filename);
88 DmxMailbox::~DmxMailbox (void)
96 DmxMailbox::loadMessages (void)
99 DtMailBoolean moreMessages = DTM_TRUE;
100 DtMail::Session *session = theRoamApp.session()->session();
102 // try to construct _mbox
103 _mbox = session->mailBoxConstruct (
111 if (handleError (env, "new DtMail::MailBox") == DTM_TRUE)
115 // (O_RDONLY for now)
116 _mbox->open (env, /* DtMailEnv */
117 DTM_FALSE, /* auto_create */
118 O_RDONLY, /* open(2) flag */
119 (mode_t) 0, /* create(2) mode */
120 DTM_FALSE, /* lock_flag */
121 DTM_TRUE /* auto_parse */
124 if (handleError (env, "open mailbox") == DTM_TRUE)
127 // get the first message handle
128 DtMailMessageHandle first = NULL, next = NULL, prev = NULL;
129 DtMailHeaderRequest request;
130 DtMailHeaderLine hdrline;
132 DtMail::Message *m = NULL; // temporary
134 createHeaderRequest (request);
136 first = _mbox->getFirstMessageSummary (env, request, hdrline);
138 if (handleError (env, "get first msg summary") == DTM_TRUE)
144 "loadMessages: error w/1st message...exiting.\n");
148 // this makes hash of the caching strategy, but oh well....
149 m = _mbox->getMessage (env, first);
150 if (handleError (env, "get first msg") == DTM_TRUE)
152 _messages [i].setMessage (m);
156 _messages [i].setHandle (first);
157 _messages [i].setHeader (hdrline);
159 while (moreMessages == DTM_TRUE)
161 next = _mbox->getNextMessageSummary (env, prev,
166 moreMessages = DTM_FALSE;
167 if (handleError (env, "msgLoop") == DTM_TRUE)
169 break; // break out if error
172 _messages [i].setHandle (next);
173 _messages [i].setHeader (hdrline);
182 // fill in the remaining message structures .. temporary, honest!
183 for (int j = _firstIndex; j <= _messageCount; j++)
185 m = _mbox->getMessage (env, _messages [j].msgHandle);
186 if (handleError (env, "getMessage loop") == DTM_TRUE)
188 printf ("fatal error...bailing...\n");
191 _messages [j].setMessage (m);
194 sprintf (tmp, "%d", j); // ick
195 _messages [j].setInfo (tmp);
198 // free header request structure
200 // this assumes that you have allocated all of the possible headers
201 // in the DmxHeaders -- a bad assumption, but currently true
202 for (k = 0; k < DMXNUMHDRS; k++)
204 free (request.header_name [k]);
206 delete request.header_name;
212 DmxMailbox::createHeaderRequest (DtMailHeaderRequest &request)
214 // set up default headers
215 request.number_of_names = DMXNUMHDRS;
216 request.header_name = new (char* [DMXNUMHDRS]);
217 request.header_name[DMXCC] = strdup(DtMailMessageCc);
218 request.header_name[DMXFROM] = strdup(DtMailMessageSender);
219 request.header_name[DMXSUBJ] = strdup(DtMailMessageSubject);
220 request.header_name[DMXDATE] = strdup(DtMailMessageReceivedTime);
221 request.header_name[DMXCLENGTH] = strdup(DtMailMessageContentLength);
222 request.header_name[DMXSTATUS] = strdup(DtMailMessageStatus);
223 request.header_name[DMXTO] = strdup(DtMailMessageTo);
224 request.header_name[DMXV3CHARSET] = strdup(DtMailMessageV3charset);
225 request.header_name[DMXCONTENTTYPE] = strdup(DtMailMessageContentType);
231 DmxMailbox::printMailboxInfo (void)
233 printf ("\"%s\": %d messages\n", _fileName, _messageCount);