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
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);
87 DmxMailbox::~DmxMailbox (void)
95 DmxMailbox::loadMessages (void)
98 DtMailBoolean moreMessages = DTM_TRUE;
99 DtMail::Session *session = theRoamApp.session()->session();
101 // try to construct _mbox
102 _mbox = session->mailBoxConstruct (
110 if (handleError (env, "new DtMail::MailBox") == DTM_TRUE)
114 // (O_RDONLY for now)
115 _mbox->open (env, /* DtMailEnv */
116 DTM_FALSE, /* auto_create */
117 O_RDONLY, /* open(2) flag */
118 (mode_t) 0, /* create(2) mode */
119 DTM_FALSE, /* lock_flag */
120 DTM_TRUE /* auto_parse */
123 if (handleError (env, "open mailbox") == DTM_TRUE)
126 // get the first message handle
127 DtMailMessageHandle first = NULL, next = NULL, prev = NULL;
128 DtMailHeaderRequest request;
129 DtMailHeaderLine hdrline;
131 DtMail::Message *m = NULL; // temporary
133 createHeaderRequest (request);
135 first = _mbox->getFirstMessageSummary (env, request, hdrline);
137 if (handleError (env, "get first msg summary") == DTM_TRUE)
143 "loadMessages: error w/1st message...exiting.\n");
147 // this makes hash of the caching strategy, but oh well....
148 m = _mbox->getMessage (env, first);
149 if (handleError (env, "get first msg") == DTM_TRUE)
151 _messages [i].setMessage (m);
155 _messages [i].setHandle (first);
156 _messages [i].setHeader (hdrline);
158 while (moreMessages == DTM_TRUE)
160 next = _mbox->getNextMessageSummary (env, prev,
165 moreMessages = DTM_FALSE;
166 if (handleError (env, "msgLoop") == DTM_TRUE)
168 break; // break out if error
171 _messages [i].setHandle (next);
172 _messages [i].setHeader (hdrline);
181 // fill in the remaining message structures .. temporary, honest!
182 for (int j = _firstIndex; j <= _messageCount; j++)
184 m = _mbox->getMessage (env, _messages [j].msgHandle);
185 if (handleError (env, "getMessage loop") == DTM_TRUE)
187 printf ("fatal error...bailing...\n");
190 _messages [j].setMessage (m);
193 sprintf (tmp, "%d", j); // ick
194 _messages [j].setInfo (tmp);
197 // free header request structure
199 // this assumes that you have allocated all of the possible headers
200 // in the DmxHeaders -- a bad assumption, but currently true
201 for (k = 0; k < DMXNUMHDRS; k++)
203 free (request.header_name [k]);
205 delete request.header_name;
211 DmxMailbox::createHeaderRequest (DtMailHeaderRequest &request)
213 // set up default headers
214 request.number_of_names = DMXNUMHDRS;
215 request.header_name = new (char* [DMXNUMHDRS]);
216 request.header_name[DMXCC] = strdup(DtMailMessageCc);
217 request.header_name[DMXFROM] = strdup(DtMailMessageSender);
218 request.header_name[DMXSUBJ] = strdup(DtMailMessageSubject);
219 request.header_name[DMXDATE] = strdup(DtMailMessageReceivedTime);
220 request.header_name[DMXCLENGTH] = strdup(DtMailMessageContentLength);
221 request.header_name[DMXSTATUS] = strdup(DtMailMessageStatus);
222 request.header_name[DMXTO] = strdup(DtMailMessageTo);
223 request.header_name[DMXV3CHARSET] = strdup(DtMailMessageV3charset);
224 request.header_name[DMXCONTENTTYPE] = strdup(DtMailMessageContentType);
230 DmxMailbox::printMailboxInfo (void)
232 printf ("\"%s\": %d messages\n", _fileName, _messageCount);