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 <DtHelp/LocaleXlate.h>
57 #include <EUSCompat.h>
59 #include "utils/str_utils.h"
64 // initialize everything
68 cachedValues = B_FALSE;
70 hasAttachments = B_FALSE;
73 msgHeader.header_values = NULL;
74 msgHeader.number_of_names = 0;
81 DmxMsg::setHandle (DtMailMessageHandle &h)
88 DmxMsg::setHeader (DtMailHeaderLine &h)
95 DmxMsg::setMessage (DtMail::Message *m)
102 DmxMsg::setInfo (char *info)
104 addlInfo = strdup (info);
109 DmxMsg::getFlags (void)
112 DtMailBoolean flagState;
114 memset (&env, '\0', sizeof (DtMailEnv));
115 flagState = DTM_FALSE;
120 flagState = message->flagIsSet (env, DtMailMessageMultipart);
121 if (handleError (env, "msg: multipart?") == B_TRUE)
124 if (flagState == DTM_TRUE)
126 hasAttachments = B_TRUE;
128 hasAttachments = B_FALSE;
131 flagState = message->flagIsSet (env, DtMailMessageNew);
132 if (handleError (env, "msg: new?") == B_TRUE)
135 if (flagState == DTM_TRUE)
149 DmxMsg::printHeader (enum DmxHeaderType htype)
152 char *status, *indicator;
154 if (isCurrent == B_TRUE)
165 status = "O"; // how about "unread" ??
168 if (hasAttachments == B_TRUE)
173 // the addlInfo string is any extra info needed by the
174 // viewer, such as a message number
176 char *buffer = new char [1024];
177 memset (buffer, 0, 1024);
182 sprintf (buffer, "%s%s%s %s",
183 indicator, status, addlInfo,
184 formatHeader (msgHeader, MSGLIST));
187 sprintf (buffer, "%s",
188 formatHeader (msgHeader, MSGHEADER));
191 printf ("error in DmxMsg::display\n");
201 DmxMsg::display (void)
204 boolean_t FirstIsText = B_FALSE;
205 DtMail::BodyPart *firstPart = NULL, *nextpart = NULL;
207 char *description = NULL;
208 char *sunDataDescription = NULL;
210 void * contents = NULL;
211 unsigned long length = 0;
215 char *mime_cs = NULL, *from_cs = NULL, *to_cs = NULL;
216 char *v3_cs = new char [64];
218 if (cachedValues != B_TRUE)
219 parse (); // read in body part info
221 firstPart = bodyParts [0];
223 firstPart->getContents(env,
224 (const void **) &contents,
231 if (handleError (env, "getContents") == B_TRUE)
236 DtMailValueSeq value;
237 boolean_t err = B_FALSE;
239 // Get the bodypart's charset - Try MIME first then V3
240 firstPart->getHeader(env, DtMailMessageContentType, DTM_TRUE, value);
241 if (env.isNotSet()) {
242 mime_cs = firstPart->csFromContentType(value);
246 firstPart->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value);
247 if (env.isNotSet()) {
248 strcpy(v3_cs, *(value[0]));
255 // If cannot obtain bodypart's charset header, then maybe this message
256 // has only one bodypart, then in this case the charset header maybe
257 // among the message's envelope (main message headers).
258 // Get the envelope of the message (in order to access the headers)
259 DtMail::Envelope *envelope = NULL;
261 envelope = message->getEnvelope(env);
264 env.logError(DTM_FALSE, "DEBUG dtmailpr: Looking at main message header\n");
267 if (envelope != NULL) {
268 // Check for MIME charset header and then for V3 charset header
269 envelope->getHeader(env, DtMailMessageContentType, DTM_TRUE, value);
270 if (env.isNotSet()) {
271 mime_cs = firstPart->csFromContentType(value);
276 if (mime_cs == NULL || err == B_TRUE) {
278 envelope->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value);
279 if (env.isNotSet()) {
280 strcpy(v3_cs, *(value[0]));
288 env.logError(DTM_FALSE, "DEBUG dtmailpr: envelope is null\n");
293 // Default codeset in case mime_cs and v3_cs are both null.
294 if ((mime_cs == NULL) && (strlen(v3_cs) == 0)) {
296 firstPart->DtXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,
297 setlocale(LC_CTYPE, NULL),
301 strcpy(v3_cs, "DEFAULT");
307 // Get iconv from and to codeset and do conversion.
310 from_cs = firstPart->csToConvName(mime_cs);
312 env.logError(DTM_FALSE, "DEBUG dtmailpr: mime_cs = %s\n", mime_cs);
315 from_cs = firstPart->csToConvName(v3_cs);
317 env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs);
320 to_cs = firstPart->locToConvName();
323 if ( from_cs == NULL )
324 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs is NULL\n");
326 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs = %s\n", from_cs);
329 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs is NULL\n");
331 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs = %s\n", to_cs);
334 if ( from_cs && to_cs ) {
335 if ( strcasecmp(from_cs, to_cs) != 0 ) {
336 converted = firstPart->csConvert((char **)&contents, length, 0, from_cs, to_cs);
338 env.logError(DTM_FALSE, "DEBUG dtmailpr: converted = %d\n", converted);
349 // End of For CHARSET
352 buf = new char [length + 1];
353 memset (buf, 0, (size_t) length + 1);
355 // have to "seek" length bytes into the
357 memmove (buf, contents, (size_t) length);
358 buf [length] = '\0'; // null-terminate
362 if (converted && contents)
365 char *numbuf = new char [10241];
366 memset (numbuf, 0, 1024);
369 // Don't want "Message 1:" appearing in print output
370 sprintf (numbuf, "Messsage %s:\n%s\n",
371 addlInfo, printHeader (MSGHEADER));
373 puts(printHeader(MSGHEADER));
378 // No attachments? We're done.
387 for (i = 1; i < numBPs ; i++)
389 nextpart = bodyParts [i];
391 if (nextpart == NULL)
392 fprintf (stderr, "Error getting part!\n");
396 sunDataDescription = "";
401 nextpart->getContents(env, NULL, &length, &type,
402 &name, &mode, &sunDataDescription);
403 if (handleError (env, "getContents") == B_TRUE)
409 if (sunDataDescription == NULL)
413 // should add bracket or something
414 attbuf = new char [strlen (sunDataDescription) +10];
415 sprintf (attbuf, " (%s)", sunDataDescription);
416 description = attbuf;
422 printf ("[%d] \"%s\"%s, ", i, name, description);
423 printf ("%s, %lu bytes\n", type, length);
437 // store the body parts for later reference
440 boolean_t FirstIsText = B_FALSE;
441 DtMail::BodyPart *part = NULL, *nextpart = NULL;
442 char *type = NULL, *attr = NULL;
444 int bc = message->getBodyCount (env);
445 if (handleError (env, "getBodyCount") == B_TRUE)
448 part = message->getFirstBodyPart (env);
449 if (handleError (env, "getFirstBodyPart") == B_TRUE)
452 part->getContents (env, NULL, NULL, &type, NULL, NULL, NULL);
453 if (handleError (env, "getContents") == B_TRUE)
456 bodyParts = new (DtMail::BodyPart *[bc]);
457 cachedValues = B_TRUE;
460 bodyParts [0] = part;
466 attr = DtDtsDataTypeToAttributeValue (type,
471 FirstIsText = B_TRUE;
473 //free (type); // it's allocating some data for us
475 FirstIsText = B_FALSE;
478 // No attachments? We're done.
484 for (i = 1; i < bc; i++)
487 nextpart = message->getNextBodyPart (env,
489 if (handleError (env, "getNextBodyPart") == B_TRUE)
492 if (nextpart == NULL)
493 fprintf (stderr, "Error getting part!\n");
496 bodyParts [i] = nextpart;