1 /* $TOG: message.C /main/9 1998/07/24 16:08:20 mgreess $
3 * (c) Copyright 1996 Digital Equipment Corporation.
4 * (c) Copyright 1996 Hewlett-Packard Company.
5 * (c) Copyright 1996 International Business Machines Corp.
6 * (c) Copyright 1994,1996 Sun Microsystems, Inc.
7 * (c) Copyright 1996 Novell, Inc.
8 * (c) Copyright 1996 FUJITSU LIMITED.
9 * (c) Copyright 1996 Hitachi.
15 * RESTRICTED CONFIDENTIAL INFORMATION:
17 * The information in this document is subject to special
18 * restrictions in a confidential disclosure agreement between
19 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
20 * document outside HP, IBM, Sun, USL, SCO, or Univel without
21 * Sun's specific written approval. This document and all copies
22 * and derivative works thereof must be returned or destroyed at
30 #include <DtHelp/LocaleXlate.h>
32 #if !defined(USL) && !defined(__uxp__)
35 #include <EUSCompat.h>
37 #include "utils/str_utils.h"
42 // initialize everything
46 cachedValues = B_FALSE;
48 hasAttachments = B_FALSE;
55 DmxMsg::setHandle (DtMailMessageHandle &h)
62 DmxMsg::setHeader (DtMailHeaderLine &h)
69 DmxMsg::setMessage (DtMail::Message *m)
76 DmxMsg::setInfo (char *info)
78 addlInfo = strdup (info);
83 DmxMsg::getFlags (void)
86 DtMailBoolean flagState;
88 memset (&env, '\0', sizeof (DtMailEnv));
89 flagState = DTM_FALSE;
94 flagState = message->flagIsSet (env, DtMailMessageMultipart);
95 if (handleError (env, "msg: multipart?") == B_TRUE)
98 if (flagState == DTM_TRUE)
100 hasAttachments = B_TRUE;
102 hasAttachments = B_FALSE;
105 flagState = message->flagIsSet (env, DtMailMessageNew);
106 if (handleError (env, "msg: new?") == B_TRUE)
109 if (flagState == DTM_TRUE)
123 DmxMsg::printHeader (enum DmxHeaderType htype)
126 char *status, *indicator;
128 if (isCurrent == B_TRUE)
139 status = "O"; // how about "unread" ??
142 if (hasAttachments == B_TRUE)
147 // the addlInfo string is any extra info needed by the
148 // viewer, such as a message number
150 char *buffer = new char [1024];
151 memset (buffer, 0, 1024);
156 sprintf (buffer, "%s%s%s %s",
157 indicator, status, addlInfo,
158 formatHeader (msgHeader, MSGLIST));
161 sprintf (buffer, "%s",
162 formatHeader (msgHeader, MSGHEADER));
165 printf ("error in DmxMsg::display\n");
175 DmxMsg::display (void)
178 boolean_t FirstIsText = B_FALSE;
179 DtMail::BodyPart *firstPart = NULL, *nextpart = NULL;
181 char *description = NULL;
182 char *sunDataDescription = NULL;
184 void * contents = NULL;
185 unsigned long length = 0;
189 char *mime_cs = NULL, *from_cs = NULL, *to_cs = NULL;
190 char *v3_cs = new char [64];
192 if (cachedValues != B_TRUE)
193 parse (); // read in body part info
195 firstPart = bodyParts [0];
197 firstPart->getContents(env,
198 (const void **) &contents,
205 if (handleError (env, "getContents") == B_TRUE)
210 DtMailValueSeq value;
211 boolean_t err = B_FALSE;
213 // Get the bodypart's charset - Try MIME first then V3
214 firstPart->getHeader(env, DtMailMessageContentType, DTM_TRUE, value);
215 if (env.isNotSet()) {
216 mime_cs = firstPart->csFromContentType(value);
220 firstPart->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value);
221 if (env.isNotSet()) {
222 strcpy(v3_cs, *(value[0]));
229 // If cannot obtain bodypart's charset header, then maybe this message
230 // has only one bodypart, then in this case the charset header maybe
231 // among the message's envelope (main message headers).
232 // Get the envelope of the message (in order to access the headers)
233 DtMail::Envelope *envelope = NULL;
235 envelope = message->getEnvelope(env);
238 env.logError(DTM_FALSE, "DEBUG dtmailpr: Looking at main message header\n");
241 if (envelope != NULL) {
242 // Check for MIME charset header and then for V3 charset header
243 envelope->getHeader(env, DtMailMessageContentType, DTM_TRUE, value);
244 if (env.isNotSet()) {
245 mime_cs = firstPart->csFromContentType(value);
250 if (mime_cs == NULL || err == B_TRUE) {
252 envelope->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value);
253 if (env.isNotSet()) {
254 strcpy(v3_cs, *(value[0]));
262 env.logError(DTM_FALSE, "DEBUG dtmailpr: envelope is null\n");
267 // Default codeset in case mime_cs and v3_cs are both null.
268 if ((mime_cs == NULL) && (strlen(v3_cs) == 0)) {
270 firstPart->DtXlateOpToStdLocale(DtLCX_OPER_SETLOCALE,
271 setlocale(LC_CTYPE, NULL),
275 strcpy(v3_cs, "DEFAULT");
282 // Get iconv from and to codeset and do conversion.
285 from_cs = firstPart->csToConvName(mime_cs);
287 env.logError(DTM_FALSE, "DEBUG dtmailpr: mime_cs = %s\n", mime_cs);
290 from_cs = firstPart->csToConvName(v3_cs);
292 env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs);
295 to_cs = firstPart->locToConvName();
298 if ( from_cs == NULL )
299 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs is NULL\n");
301 env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs = %s\n", from_cs);
304 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs is NULL\n");
306 env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs = %s\n", to_cs);
309 if ( from_cs && to_cs ) {
310 if ( strcasecmp(from_cs, to_cs) != 0 ) {
311 converted = firstPart->csConvert((char **)&contents, length, 0, from_cs, to_cs);
313 env.logError(DTM_FALSE, "DEBUG dtmailpr: converted = %d\n", converted);
324 // End of For CHARSET
327 buf = new char [length + 1];
328 memset (buf, 0, (size_t) length + 1);
330 // have to "seek" length bytes into the
332 memmove (buf, contents, (size_t) length);
333 buf [length] = '\0'; // null-terminate
337 if (converted && contents)
340 char *numbuf = new char [10241];
341 memset (numbuf, 0, 1024);
344 // Don't want "Message 1:" appearing in print output
345 sprintf (numbuf, "Messsage %s:\n%s\n",
346 addlInfo, printHeader (MSGHEADER));
348 puts(printHeader(MSGHEADER));
353 // No attachments? We're done.
362 for (i = 1; i < numBPs ; i++)
364 nextpart = bodyParts [i];
366 if (nextpart == NULL)
367 fprintf (stderr, "Error getting part!\n");
371 sunDataDescription = "";
376 nextpart->getContents(env, NULL, &length, &type,
377 &name, &mode, &sunDataDescription);
378 if (handleError (env, "getContents") == B_TRUE)
384 if (sunDataDescription == NULL)
388 // should add bracket or something
389 attbuf = new char [strlen (sunDataDescription) +10];
390 sprintf (attbuf, " (%s)", sunDataDescription);
391 description = attbuf;
397 printf ("[%d] \"%s\"%s, ", i, name, description);
398 printf ("%s, %d bytes\n", type, length);
412 // store the body parts for later reference
415 boolean_t FirstIsText = B_FALSE;
416 DtMail::BodyPart *part = NULL, *nextpart = NULL;
417 char *type = NULL, *attr = NULL;
419 int bc = message->getBodyCount (env);
420 if (handleError (env, "getBodyCount") == B_TRUE)
423 part = message->getFirstBodyPart (env);
424 if (handleError (env, "getFirstBodyPart") == B_TRUE)
427 part->getContents (env, NULL, NULL, &type, NULL, NULL, NULL);
428 if (handleError (env, "getContents") == B_TRUE)
431 bodyParts = new (DtMail::BodyPart *[bc]);
432 cachedValues = B_TRUE;
435 bodyParts [0] = part;
441 attr = DtDtsDataTypeToAttributeValue (type,
446 FirstIsText = B_TRUE;
448 //free (type); // it's allocating some data for us
450 FirstIsText = B_FALSE;
453 // No attachments? We're done.
459 for (i = 1; i < bc; i++)
462 nextpart = message->getNextBodyPart (env,
464 if (handleError (env, "getNextBodyPart") == B_TRUE)
467 if (nextpart == NULL)
468 fprintf (stderr, "Error getting part!\n");
471 bodyParts [i] = nextpart;