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 /* $TOG: message.C /main/9 1998/07/24 16:08:20 mgreess $
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1996 Hewlett-Packard Company.
27 * (c) Copyright 1996 International Business Machines Corp.
28 * (c) Copyright 1994,1996 Sun Microsystems, Inc.
29 * (c) Copyright 1996 Novell, Inc.
30 * (c) Copyright 1996 FUJITSU LIMITED.
31 * (c) Copyright 1996 Hitachi.
37 * RESTRICTED CONFIDENTIAL INFORMATION:
39 * The information in this document is subject to special
40 * restrictions in a confidential disclosure agreement between
41 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
42 * document outside HP, IBM, Sun, USL, SCO, or Univel without
43 * Sun's specific written approval. This document and all copies
44 * and derivative works thereof must be returned or destroyed at
52 #include <Dt/LocaleXlate.h>
55 #include "utils/str_utils.h"
60 // initialize everything
64 cachedValues = B_FALSE;
66 hasAttachments = B_FALSE;
69 msgHeader.header_values = NULL;
70 msgHeader.number_of_names = 0;
77 DmxMsg::setHandle (DtMailMessageHandle &h)
84 DmxMsg::setHeader (DtMailHeaderLine &h)
91 DmxMsg::setMessage (DtMail::Message *m)
98 DmxMsg::setInfo (char *info)
100 addlInfo = strdup (info);
105 DmxMsg::getFlags (void)
108 DtMailBoolean flagState;
110 memset (&env, '\0', sizeof (DtMailEnv));
111 flagState = DTM_FALSE;
116 flagState = message->flagIsSet (env, DtMailMessageMultipart);
117 if (handleError (env, "msg: multipart?") == B_TRUE)
120 if (flagState == DTM_TRUE)
122 hasAttachments = B_TRUE;
124 hasAttachments = B_FALSE;
127 flagState = message->flagIsSet (env, DtMailMessageNew);
128 if (handleError (env, "msg: new?") == B_TRUE)
131 if (flagState == DTM_TRUE)
145 DmxMsg::printHeader (enum DmxHeaderType htype)
148 char *status, *indicator;
150 if (isCurrent == B_TRUE)
161 status = "O"; // how about "unread" ??
164 if (hasAttachments == B_TRUE)
169 // the addlInfo string is any extra info needed by the
170 // viewer, such as a message number
172 char *buffer = new char [1024];
173 memset (buffer, 0, 1024);
178 sprintf (buffer, "%s%s%s %s",
179 indicator, status, addlInfo,
180 formatHeader (msgHeader, MSGLIST));
183 sprintf (buffer, "%s",
184 formatHeader (msgHeader, MSGHEADER));
187 printf ("error in DmxMsg::display\n");
197 DmxMsg::display (void)
200 boolean_t FirstIsText = B_FALSE;
201 DtMail::BodyPart *firstPart = NULL, *nextpart = NULL;
203 char *description = NULL;
204 char *sunDataDescription = NULL;
206 void * contents = NULL;
207 unsigned long length = 0;
211 char *mime_cs = NULL, *from_cs = NULL, *to_cs = NULL;
212 char *v3_cs = new char [64];
214 if (cachedValues != B_TRUE)
215 parse (); // read in body part info
217 firstPart = bodyParts [0];
219 firstPart->getContents(env,
220 (const void **) &contents,
227 if (handleError (env, "getContents") == B_TRUE)
232 DtMailValueSeq value;
233 boolean_t err = B_FALSE;
235 // Get the bodypart's charset - Try MIME first then V3
236 firstPart->getHeader(env, DtMailMessageContentType, DTM_TRUE, value);
237 if (env.isNotSet()) {
238 mime_cs = firstPart->csFromContentType(value);
242 firstPart->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value);
243 if (env.isNotSet()) {
244 strcpy(v3_cs, *(value[0]));
251 // If cannot obtain bodypart's charset header, then maybe this message
252 // has only one bodypart, then in this case the charset header maybe
253 // among the message's envelope (main message headers).
254 // Get the envelope of the message (in order to access the headers)
255 DtMail::Envelope *envelope = NULL;
257 envelope = message->getEnvelope(env);
260 env.logError(DTM_FALSE, "DEBUG dtmailpr: Looking at main message header\n");
263 if (envelope != NULL) {
264 // Check for MIME charset header and then for V3 charset header
265 envelope->getHeader(env, DtMailMessageContentType, DTM_TRUE, value);
266 if (env.isNotSet()) {
267 mime_cs = firstPart->csFromContentType(value);
272 if (mime_cs == NULL || err == B_TRUE) {
274 envelope->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value);
275 if (env.isNotSet()) {
276 strcpy(v3_cs, *(value[0]));
284 env.logError(DTM_FALSE, "DEBUG dtmailpr: envelope is null\n");
289 // Default codeset in case mime_cs and v3_cs are both null.
290 if ((mime_cs == NULL) && (strlen(v3_cs) == 0)) {
292 firstPart->DtXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,
293 setlocale(LC_CTYPE, NULL),
297 strcpy(v3_cs, "DEFAULT");
303 // Get iconv from and to codeset and do conversion.
306 from_cs = firstPart->csToConvName(mime_cs);
308 env.logError(DTM_FALSE, "DEBUG dtmailpr: mime_cs = %s\n", mime_cs);
311 from_cs = firstPart->csToConvName(v3_cs);
313 env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs);
316 to_cs = firstPart->locToConvName();
319 if ( from_cs == NULL )
320 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs is NULL\n");
322 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs = %s\n", from_cs);
325 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs is NULL\n");
327 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs = %s\n", to_cs);
330 if ( from_cs && to_cs ) {
331 if ( strcasecmp(from_cs, to_cs) != 0 ) {
332 converted = firstPart->csConvert((char **)&contents, length, 0, from_cs, to_cs);
334 env.logError(DTM_FALSE, "DEBUG dtmailpr: converted = %d\n", converted);
345 // End of For CHARSET
348 buf = new char [length + 1];
349 memset (buf, 0, (size_t) length + 1);
351 // have to "seek" length bytes into the
353 memmove (buf, contents, (size_t) length);
354 buf [length] = '\0'; // null-terminate
358 if (converted && contents)
361 char *numbuf = new char [10241];
362 memset (numbuf, 0, 1024);
365 // Don't want "Message 1:" appearing in print output
366 sprintf (numbuf, "Messsage %s:\n%s\n",
367 addlInfo, printHeader (MSGHEADER));
369 puts(printHeader(MSGHEADER));
374 // No attachments? We're done.
383 for (i = 1; i < numBPs ; i++)
385 nextpart = bodyParts [i];
387 if (nextpart == NULL)
388 fprintf (stderr, "Error getting part!\n");
392 sunDataDescription = "";
397 nextpart->getContents(env, NULL, &length, &type,
398 &name, &mode, &sunDataDescription);
399 if (handleError (env, "getContents") == B_TRUE)
405 if (sunDataDescription == NULL)
409 // should add bracket or something
410 attbuf = new char [strlen (sunDataDescription) +10];
411 sprintf (attbuf, " (%s)", sunDataDescription);
412 description = attbuf;
418 printf ("[%d] \"%s\"%s, ", i, name, description);
419 printf ("%s, %lu bytes\n", type, length);
433 // store the body parts for later reference
436 boolean_t FirstIsText = B_FALSE;
437 DtMail::BodyPart *part = NULL, *nextpart = NULL;
438 char *type = NULL, *attr = NULL;
440 int bc = message->getBodyCount (env);
441 if (handleError (env, "getBodyCount") == B_TRUE)
444 part = message->getFirstBodyPart (env);
445 if (handleError (env, "getFirstBodyPart") == B_TRUE)
448 part->getContents (env, NULL, NULL, &type, NULL, NULL, NULL);
449 if (handleError (env, "getContents") == B_TRUE)
452 bodyParts = new (DtMail::BodyPart *[bc]);
453 cachedValues = B_TRUE;
456 bodyParts [0] = part;
462 attr = DtDtsDataTypeToAttributeValue (type,
467 FirstIsText = B_TRUE;
469 //free (type); // it's allocating some data for us
471 FirstIsText = B_FALSE;
474 // No attachments? We're done.
480 for (i = 1; i < bc; i++)
483 nextpart = message->getNextBodyPart (env,
485 if (handleError (env, "getNextBodyPart") == B_TRUE)
488 if (nextpart == NULL)
489 fprintf (stderr, "Error getting part!\n");
492 bodyParts [i] = nextpart;