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 /* $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>
54 #if !defined(USL) && !defined(__uxp__)
57 #include <EUSCompat.h>
59 #include "utils/str_utils.h"
64 // initialize everything
68 cachedValues = B_FALSE;
70 hasAttachments = B_FALSE;
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");
304 // Get iconv from and to codeset and do conversion.
307 from_cs = firstPart->csToConvName(mime_cs);
309 env.logError(DTM_FALSE, "DEBUG dtmailpr: mime_cs = %s\n", mime_cs);
312 from_cs = firstPart->csToConvName(v3_cs);
314 env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs);
317 to_cs = firstPart->locToConvName();
320 if ( from_cs == NULL )
321 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs is NULL\n");
323 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs = %s\n", from_cs);
326 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs is NULL\n");
328 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs = %s\n", to_cs);
331 if ( from_cs && to_cs ) {
332 if ( strcasecmp(from_cs, to_cs) != 0 ) {
333 converted = firstPart->csConvert((char **)&contents, length, 0, from_cs, to_cs);
335 env.logError(DTM_FALSE, "DEBUG dtmailpr: converted = %d\n", converted);
346 // End of For CHARSET
349 buf = new char [length + 1];
350 memset (buf, 0, (size_t) length + 1);
352 // have to "seek" length bytes into the
354 memmove (buf, contents, (size_t) length);
355 buf [length] = '\0'; // null-terminate
359 if (converted && contents)
362 char *numbuf = new char [10241];
363 memset (numbuf, 0, 1024);
366 // Don't want "Message 1:" appearing in print output
367 sprintf (numbuf, "Messsage %s:\n%s\n",
368 addlInfo, printHeader (MSGHEADER));
370 puts(printHeader(MSGHEADER));
375 // No attachments? We're done.
384 for (i = 1; i < numBPs ; i++)
386 nextpart = bodyParts [i];
388 if (nextpart == NULL)
389 fprintf (stderr, "Error getting part!\n");
393 sunDataDescription = "";
398 nextpart->getContents(env, NULL, &length, &type,
399 &name, &mode, &sunDataDescription);
400 if (handleError (env, "getContents") == B_TRUE)
406 if (sunDataDescription == NULL)
410 // should add bracket or something
411 attbuf = new char [strlen (sunDataDescription) +10];
412 sprintf (attbuf, " (%s)", sunDataDescription);
413 description = attbuf;
419 printf ("[%d] \"%s\"%s, ", i, name, description);
420 printf ("%s, %d bytes\n", type, length);
434 // store the body parts for later reference
437 boolean_t FirstIsText = B_FALSE;
438 DtMail::BodyPart *part = NULL, *nextpart = NULL;
439 char *type = NULL, *attr = NULL;
441 int bc = message->getBodyCount (env);
442 if (handleError (env, "getBodyCount") == B_TRUE)
445 part = message->getFirstBodyPart (env);
446 if (handleError (env, "getFirstBodyPart") == B_TRUE)
449 part->getContents (env, NULL, NULL, &type, NULL, NULL, NULL);
450 if (handleError (env, "getContents") == B_TRUE)
453 bodyParts = new (DtMail::BodyPart *[bc]);
454 cachedValues = B_TRUE;
457 bodyParts [0] = part;
463 attr = DtDtsDataTypeToAttributeValue (type,
468 FirstIsText = B_TRUE;
470 //free (type); // it's allocating some data for us
472 FirstIsText = B_FALSE;
475 // No attachments? We're done.
481 for (i = 1; i < bc; i++)
484 nextpart = message->getNextBodyPart (env,
486 if (handleError (env, "getNextBodyPart") == B_TRUE)
489 if (nextpart == NULL)
490 fprintf (stderr, "Error getting part!\n");
493 bodyParts [i] = nextpart;