コード例 #1
0
ファイル: RFCFormat.C プロジェクト: juddy/edcde
void
RFCFormat::writeHeaders(DtMailEnv & error,
			DtMail::Message & msg,
			DtMailBoolean include_unix_from,
			const char * extra_headers,
			const char ** suppress_headers,
			Buffer & buf)
{
    error.clear();

    // First we copy each header from the message to the
    // buffer. The headers may need encoding to put them away, so
    // we will apply RFC1522 if necessary.
    //
    DtMailHeaderHandle hnd;
    DtMail::Envelope * env = msg.getEnvelope(error);
    if (error.isSet()) {
	return;
    }

    char * name = NULL;
    DtMailValueSeq value;

    hnd = env->getFirstHeader(error, &name, value);
    if (!hnd || error.isSet()) {
	return;
    }

    if (include_unix_from &&
	(error.isSet() || strcmp(name, "From") != 0)) {
	// We require a Unix from line, and we don't have one.
	// we will make one up using the sender, and the current
	// date.
	//
	char *unix_from = new char[100];
	strcpy(unix_from, "From ");
	
	DtMailValueSeq sender;
	env->getHeader(error, DtMailMessageSender, DTM_TRUE, sender);
	if (error.isSet()) {
	    // We no longer know who this is really from.
	    //
	    strcat(unix_from, "nobody@nowhere");
	}
	else {
	    DtMailAddressSeq * addrSeq = sender[0]->toAddress();
	    
	    strcat(unix_from, (*addrSeq)[0]->dtm_address);
	    delete addrSeq;
	}
	error.clear();

	time_t now = time(NULL);
	char time_format[30];
	
	SafeCtime(&now, time_format, sizeof(time_format));
	
	strcat(unix_from, " ");
	strcat(unix_from, time_format);
	buf.appendData(unix_from, strlen(unix_from));
	delete [] unix_from;
    }
    else {
	// Put out any header, except Unix From line
	//
	if (strcmp(name, "From") == 0) {
	    value.clear();
	    free(name);
	    hnd = env->getNextHeader(error, hnd, &name, value);
	}
    }

    for (; // First time is determined above.
	 hnd && !error.isSet();
	 value.clear(), hnd = env->getNextHeader(error, hnd, &name, value)) {

	const char **hdr;
	for (hdr = suppress_headers; *hdr; hdr++) {
	    if (strcasecmp(name, *hdr) == 0)
	      break;
	}

        //add _is_write_bcc for fixing aix defect 177096
	if (*hdr || strcasecmp(name, "bcc") == 0 && !_is_write_bcc ) {
	    free(name);
	    continue; // We will generate these headers.
	}

	int name_len = strlen(name);

	for (int val = 0; val < value.length(); val++) {
	    //
	    // If the value is null or empty do not emit this field
	    const char *valPtr;
	    for (valPtr = *(value[val]);
		 *valPtr && (isspace((unsigned char)*valPtr));
		 valPtr++)
	    {}
	    if (!*valPtr)
	      continue;
	    
	    buf.appendData(name, name_len);
	    buf.appendData(": ", 2);
	    rfc1522cpy(buf, *(value[val]));
	}

	free(name);
    }
    error.clear();

    buf.appendData(extra_headers, strlen(extra_headers));

    // Add new line that terminates the headers.
    //
    crlf(buf);
}
コード例 #2
0
Boolean
FindDialog::compareMessage(DtMailMessageHandle	  handle)
{
  Boolean				found = False;
  register unsigned int		offset;

  //
  // Check for something to do.
  //
  for (offset = 0; offset < _num_text_fields; offset++) {
    if (_text_values[offset] != NULL) {
      break;
    }
  }

  // If all fields are empty then we match anything
  if (offset >= _num_text_fields) {
	return TRUE;
  }

  if (offset < _num_text_fields && handle != NULL) {

    // TODO - CHECK ERROR!!!
    DtMailEnv		error;

    //
    // Get the mail box.
    //
    DtMail::MailBox	* mbox = _roamWindow->mailbox();

    //
    // Get the DtMail::Message and Envelope for this handle.
    //
    DtMail::Message	* message = mbox->getMessage(error, handle);
    DtMail::Envelope	* envelope = message->getEnvelope(error);

    //
    // Get the meassage header.
    //
    DtMailValueSeq	  header;

    for (offset = 0; offset < _num_text_fields; offset++) {
      if (_text_values[offset] != NULL) {
	if (_text_abstract_name[offset] != NULL) {
	  envelope->getHeader(error, _text_abstract_name[offset],
			      DTM_TRUE, header);
	  found = TRUE;
	} else {
	  envelope->getHeader(error, _text_names[offset],
			      DTM_FALSE, header);
	  found = TRUE;
	}
	if (!compareHeader(error, header, _text_values[offset])) {
	  found = False;
	  break;
	}
        else {
          // Problem: if we have multiple search fields ... and use
          // the same "header" array ... "compareHeader" looks for
          // each "find" field in each (available) header field.
          // So, make sure only one is available for searching.
          // Really "offset" should be passed to "compareHeader" ...
          // That way, correct comparison can be done and the
          // memory for this array can be released correctly via the
          // destructor .... since "remove" fails to do so.
          header.remove(0);
        }
      }
    }
    if (offset > _num_text_fields) {
      found = TRUE;
    }
  }
  return(found);
}