// // Look for all matching messages. // Boolean FindDialog::findMatching(Boolean findAll) { // TODO - CHECK ERROR!!! DtMailEnv error; unsigned int matchCount = 0; /* NL_COMMENT * This string is displayed on the find dialog status line * when searching for a matching message. */ setStatus(GETMSG(DT_catd, 1, 231, "Searching...")); busyCursor(); theRoamApp.busyAllWindows(NULL); // // Get the active list. // MsgScrollingList * displayList = _roamWindow->list(); // // Find the max. number of messages that we are to find matching. // int numberMessages = displayList->get_num_messages(); // // Are there any messages? // if (numberMessages > 0) { // // A pointer to the currently interesting message. // register DtMailMessageHandle currentHandle = NULL; // // The offset of the currentHandle in the MsgScrollingList. // register int handleOffset; // // Find the current message. We would always start from the // currently selected message. // // Get the handle to the currently displaied message. // DtMailMessageHandle initialHandle = displayList->current_msg_handle(); // // Get the list of DtMailMessageHandle's. MsgHndArray * msgHandles = displayList->get_messages(); // // Up to all of them can match, allocate and clear the list. // DtMailMessageHandle * matchList = NULL; if (findAll) { matchList = new DtMailMessageHandle[numberMessages+1]; } unsigned int matchOffset = 0; // // Deselect all messages. // XmListDeselectAllItems(displayList->baseWidget()); // // Start the search from the initially displaied message (+1). // handleOffset = displayList->position(initialHandle) - 1; if (_searchForward) { handleOffset++; if (handleOffset >= numberMessages) { handleOffset = 0; } } else { handleOffset--; if (handleOffset < 0) { handleOffset = numberMessages - 1; } } for (; handleOffset < numberMessages;) { currentHandle = msgHandles->at(handleOffset)->message_handle; // // See if this message is a match, if it is... // if (compareMessage(currentHandle)) { matchCount++; // // If we are finding all, then add to the list. // If not, then display this message and we are done. // if (findAll) { matchList[matchOffset++] = currentHandle; } else { XmListDeselectAllItems(displayList->baseWidget()); //displayList->set_selected_item_position(handleOffset); displayList->display_and_select_message(error, currentHandle); break; // Only one. } } // // If we have looped back to the initial // message (handle), then we are done. // if (currentHandle == initialHandle) { break; } // // Get the next message. // // If we have reached the end, start over. // (as if the list was a circular list) // // We loop forward (_searchForward == TRUE) else we loop backward. // if (_searchForward) { handleOffset++; if (handleOffset >= numberMessages) { handleOffset = 0; } } else { handleOffset--; if (handleOffset < 0) { handleOffset = numberMessages - 1; } } currentHandle = msgHandles->at(handleOffset)->message_handle; } // // Select all the messages that match, and display the last // one in the list. // if (findAll) { displayList->select_all_and_display_last(error, matchList, matchCount); if (matchCount > 0) { char *line = new char[80]; /* NL_COMMENT * These strings are displayed on the find dialog status line * when one or more matching messages are found. The first * string is displayed when there is one matching message, * and the second string is displayed when there is more than * one. The %d is the number of messages that matched. */ if (matchCount == 1) { strcpy(line, GETMSG(DT_catd, 1, 232, "1 message selected")); } else { sprintf(line, GETMSG(DT_catd, 1, 233, "%d messages selected"), matchCount); } setStatus(line); delete [] line; } // Clean up. delete matchList; matchList = NULL; } } normalCursor(); theRoamApp.unbusyAllWindows(); if (error.isNotSet()) { if (matchCount > 0) { if (!findAll) { clearStatus(); } return(TRUE); } } /* NL_COMMENT * This string is displayed on the find dialog status line when * no matching messages were found. */ setStatus(GETMSG(DT_catd, 1, 234, "No matches were found")); return(False); }
void DmxMsg::display ( DmxPrintHeadersEnum header_format, DmxPrintOutputProc print_proc, XtPointer stream) { DtMailEnv env; DtMailBoolean FirstIsText = DTM_FALSE; DtMail::BodyPart *firstPart = NULL, *nextpart = NULL; char *buf = NULL, *description = NULL, *name = NULL, *newline = NULL, *sunDataDescription = NULL, *type = NULL; void *contents = NULL; unsigned long length = 0; int mode = 0; // For CHARSET char v3_cs[64], *mime_cs = NULL, *from_cs = NULL, *to_cs = NULL; // read in body part info if (cachedValues != DTM_TRUE) parse (); firstPart = bodyParts [0]; firstPart->getContents(env, (const void **) &contents, &length, NULL, //type NULL, //name NULL, //mode NULL); //description if (handleError(env, "getContents") == DTM_TRUE) exit (1); // For CHARSET DtMailValueSeq value; DtMailBoolean err = DTM_FALSE; // Get the bodypart's charset - Try MIME first then V3 firstPart->getHeader(env, DtMailMessageContentType, DTM_TRUE, value); if (env.isNotSet()) { mime_cs = firstPart->csFromContentType(value); } else { env.clear(); value.clear(); firstPart->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value); if (env.isNotSet()) { strcpy(v3_cs, *(value[0])); } else { err = DTM_TRUE; env.clear(); value.clear(); } } // If cannot obtain bodypart's charset header, then maybe this message // has only one bodypart, then in this case the charset header maybe // among the message's envelope (main message headers). // Get the envelope of the message (in order to access the headers) DtMail::Envelope *envelope = NULL; if (err == DTM_TRUE) { envelope = message->getEnvelope(env); err = DTM_FALSE; #ifdef DEBUG env.logError( DTM_FALSE, "DEBUG dtmailpr: Looking at main message header\n"); #endif } // Check for MIME charset header and then for V3 charset header if (envelope != NULL) { envelope->getHeader(env, DtMailMessageContentType, DTM_TRUE, value); if (env.isNotSet()) { mime_cs = firstPart->csFromContentType(value); } else { err = DTM_TRUE; env.clear(); } if (mime_cs == NULL || err == DTM_TRUE) { value.clear(); envelope->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value); if (env.isNotSet()) { strcpy(v3_cs, *(value[0])); } else { err = DTM_TRUE; env.clear(); } } } else { #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: envelope is null\n"); #endif env.clear(); } // Default codeset in case mime_cs and v3_cs are both null. if ((mime_cs == NULL) && (strlen(v3_cs) == 0)) { char *ret = NULL; firstPart->DtXlateOpToStdLocale(DtLCX_OPER_SETLOCALE, setlocale(LC_CTYPE, NULL), NULL, NULL, &ret); strcpy(v3_cs, "DEFAULT"); strcat(v3_cs, "."); strcat(v3_cs, ret); if (ret) free(ret); } // Get iconv from and to codeset and do conversion. int converted = 0; if (mime_cs) { from_cs = firstPart->csToConvName(mime_cs); #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: mime_cs = %s\n", mime_cs); #endif } else { from_cs = firstPart->csToConvName(v3_cs); #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs); #endif } to_cs = firstPart->locToConvName(); #ifdef DEBUG if ( from_cs == NULL ) env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs is NULL\n"); else env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs = %s\n", from_cs); if ( to_cs == NULL ) env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs is NULL\n"); else env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs = %s\n", to_cs); #endif if ( from_cs && to_cs ) { if ( strcasecmp(from_cs, to_cs) != 0 ) { converted = firstPart->csConvert( (char **)&contents, length, 0, from_cs, to_cs); #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: converted = %d\n", converted); #endif } } if ( mime_cs ) free ( mime_cs ); if ( from_cs ) free( from_cs ); if ( to_cs ) free ( to_cs ); // End of For CHARSET newline = new char [2]; newline[0] = '\n'; newline[1] = '\0'; // // Print out the message headers. // buf = getPrintedHeaders(header_format); print_proc(stream, buf); print_proc(stream, newline); delete buf; // // Print out the message body. // buf = new char [length + 1]; memset (buf, 0, (unsigned int) length + 1); memmove (buf, contents, (unsigned int) length); buf [length] = '\0'; // null-terminate that puppy print_proc(stream, buf); print_proc(stream, newline); delete [] buf; // For CHARSET if (converted && contents) free(contents); // No attachments? We're done. if (numBPs < 2) return; int i = 0, attbuflen = 0; char *attbuf = NULL; char *sunbuf = NULL; print_proc(stream, newline); for (i = 1; i < numBPs ; i++) { nextpart = bodyParts [i]; if (nextpart == NULL) fprintf (stderr, "Error getting part!\n"); length = 0; type = ""; sunDataDescription = ""; description = ""; name = ""; mode = -1; nextpart->getContents(env, NULL, &length, &type, &name, &mode, &sunDataDescription); if (handleError (env, "getContents") == DTM_TRUE) exit (1); if (type == NULL) type = "(type unknown)"; if (name == NULL) name = "(name unknown)"; if (sunDataDescription == NULL) { description = ""; } else { // should add bracket or something sunbuf = new char [strlen (sunDataDescription) + 10]; sprintf(sunbuf, " (%s)", sunDataDescription); description = sunbuf; } attbuflen = strlen(name) + strlen(type) + strlen(description); attbuf = new char [attbuflen + 64]; sprintf(attbuf, "[%d] \"%s\"%s, %s, %ld bytes", i, name, description, type, length); print_proc(stream, attbuf); print_proc(stream, newline); delete [] attbuf; if (sunbuf != NULL) delete [] sunbuf; } return; }
void DmxMsg::display (void) { DtMailEnv env; boolean_t FirstIsText = B_FALSE; DtMail::BodyPart *firstPart = NULL, *nextpart = NULL; char *type; char *description = NULL; char *sunDataDescription = NULL; char *name = NULL; void * contents = NULL; unsigned long length = 0; int mode = 0; char *buf = NULL; // For CHARSET char *mime_cs = NULL, *from_cs = NULL, *to_cs = NULL; char *v3_cs = new char [64]; if (cachedValues != B_TRUE) parse (); // read in body part info firstPart = bodyParts [0]; firstPart->getContents(env, (const void **) &contents, &length, NULL, //type NULL, //name NULL, //mode NULL); //description if (handleError (env, "getContents") == B_TRUE) exit (1); // For CHARSET DtMailValueSeq value; boolean_t err = B_FALSE; // Get the bodypart's charset - Try MIME first then V3 firstPart->getHeader(env, DtMailMessageContentType, DTM_TRUE, value); if (env.isNotSet()) { mime_cs = firstPart->csFromContentType(value); } else { env.clear(); value.clear(); firstPart->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value); if (env.isNotSet()) { strcpy(v3_cs, *(value[0])); } else { err = B_TRUE; env.clear(); value.clear(); } } // If cannot obtain bodypart's charset header, then maybe this message // has only one bodypart, then in this case the charset header maybe // among the message's envelope (main message headers). // Get the envelope of the message (in order to access the headers) DtMail::Envelope *envelope = NULL; if (err == B_TRUE) { envelope = message->getEnvelope(env); err = B_FALSE; #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: Looking at main message header\n"); #endif } if (envelope != NULL) { // Check for MIME charset header and then for V3 charset header envelope->getHeader(env, DtMailMessageContentType, DTM_TRUE, value); if (env.isNotSet()) { mime_cs = firstPart->csFromContentType(value); } else { err = B_TRUE; env.clear(); } if (mime_cs == NULL || err == B_TRUE) { value.clear(); envelope->getHeader(env, DtMailMessageV3charset, DTM_TRUE, value); if (env.isNotSet()) { strcpy(v3_cs, *(value[0])); } else { err = B_TRUE; env.clear(); } } } else { #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: envelope is null\n"); #endif env.clear(); } // Default codeset in case mime_cs and v3_cs are both null. if ((mime_cs == NULL) && (strlen(v3_cs) == 0)) { char *ret = NULL; firstPart->DtXlateOpToStdLocale(DtLCX_OPER_SETLOCALE, setlocale(LC_CTYPE, NULL), NULL, NULL, &ret); strcpy(v3_cs, "DEFAULT"); strcat(v3_cs, "."); strcat(v3_cs, ret); if (ret) free(ret); } // Get iconv from and to codeset and do conversion. int converted = 0; if (mime_cs) { from_cs = firstPart->csToConvName(mime_cs); #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: mime_cs = %s\n", mime_cs); #endif } else { from_cs = firstPart->csToConvName(v3_cs); #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs); #endif } to_cs = firstPart->locToConvName(); #ifdef DEBUG if ( from_cs == NULL ) env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs is NULL\n"); else env.logError(DTM_FALSE, "DEBUG dtmailpr: from_cs = %s\n", from_cs); if ( to_cs == NULL ) env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs is NULL\n"); else env.logError(DTM_FALSE, "DEBUG dtmailpr: to_cs = %s\n", to_cs); #endif if ( from_cs && to_cs ) { if ( strcasecmp(from_cs, to_cs) != 0 ) { converted = firstPart->csConvert((char **)&contents, length, 0, from_cs, to_cs); #ifdef DEBUG env.logError(DTM_FALSE, "DEBUG dtmailpr: converted = %d\n", converted); #endif } } if ( mime_cs ) free ( mime_cs ); if ( from_cs ) free( from_cs ); if ( to_cs ) free ( to_cs ); // End of For CHARSET buf = new char [length + 1]; memset (buf, 0, (size_t) length + 1); // have to "seek" length bytes into the // contents buffer memmove (buf, contents, (size_t) length); buf [length] = '\0'; // null-terminate // that puppy // For CHARSET if (converted && contents) free(contents); char *numbuf = new char [10241]; memset (numbuf, 0, 1024); #ifdef NEVER // Don't want "Message 1:" appearing in print output sprintf (numbuf, "Messsage %s:\n%s\n", addlInfo, printHeader (MSGHEADER)); #endif puts(printHeader(MSGHEADER)); puts(buf); fflush(stdout); // No attachments? We're done. if (numBPs < 2) return; int i = 0; char *attbuf = NULL; printf ("\n"); for (i = 1; i < numBPs ; i++) { nextpart = bodyParts [i]; if (nextpart == NULL) fprintf (stderr, "Error getting part!\n"); length = 0; type = ""; sunDataDescription = ""; description = ""; name = ""; mode = -1; nextpart->getContents(env, NULL, &length, &type, &name, &mode, &sunDataDescription); if (handleError (env, "getContents") == B_TRUE) exit (1); if (type == NULL) type = "(unknown)"; if (sunDataDescription == NULL) { description = ""; } else { // should add bracket or something attbuf = new char [strlen (sunDataDescription) +10]; sprintf (attbuf, " (%s)", sunDataDescription); description = attbuf; } if (name == NULL) name = "(name)"; printf ("[%d] \"%s\"%s, ", i, name, description); printf ("%s, %d bytes\n", type, length); if (attbuf != NULL) delete [] attbuf; } delete [] v3_cs; return; }