Exemple #1
0
void
AttachArea::undeleteLastDeletedAttachment(
    DtMailEnv &mail_error
)
{

    Attachment *tmpAttachment;
    Attachment **list;
    time_t time_deleted = 0, tmpTime = 0;
    int i;

    if (_deleteCount == 0) {
	return;
    }

    list = getList();

    tmpAttachment = list[0];
    time_deleted = tmpAttachment->getBodyPart()->getDeleteTime(mail_error);
    if (mail_error.isSet()) {
	// do something
    }

    for (i=1; i<getIconCount(); i++) {
	if (list[i]->isDeleted()) {
	    tmpTime = list[i]->getBodyPart()->getDeleteTime(mail_error);
	    if (mail_error.isSet()) {
		// do something
	    }
	    if ( tmpTime > time_deleted) {
		time_deleted = tmpTime;
		tmpAttachment = list[i];
	    }
	}
    }

    tmpAttachment->undeleteIt();
    _deleteCount--;

    // Unmanage all.
    // Their positions need to get recomputed and the deleted
    // ones get remanaged in manageList().

    for (i=0; i<getIconCount(); i++) {
	list[i]->unmanageIconWidget();
    }


    this->manageList();

}
Exemple #2
0
void
RFCFormat::msgToBuffer(DtMailEnv & error,
		       DtMail::Message & msg,
		       DtMailBoolean include_content_length,
		       DtMailBoolean include_unix_from,
		       DtMailBoolean,
		       Buffer & headers,
		       Buffer & body)
{
    error.clear();

    _use_cr = DTM_TRUE;

    if (include_content_length || include_unix_from) {
	_use_cr = DTM_FALSE;
    }

    // We will format the bodies first, then the headers. The
    // reason we do this is that the result of formatting the body
    // is required for the headers. The content-type, content-length,
    // and other content based headers need to be computed before
    // being written.
    //
    char * extra_headers = NULL;
    formatBodies(error, msg, include_content_length, &extra_headers, body);
    if (error.isSet()) {
	return;
    }

    formatHeaders(error, msg, include_unix_from, extra_headers, headers);
    free(extra_headers);
    return;
}
Exemple #3
0
boolean_t
handleError (DtMailEnv &dterror, char *msg)
{
	if (dterror.isSet () == DTM_TRUE)
	{
		fprintf (stderr, "dtmailpr: (%s) %s\n", 
			msg, (const char *)dterror);
		dterror.logError (DTM_FALSE, "dtmailpr: (%s) %s\n",
			msg, (const char *)dterror);

		dterror.clear ();
		return B_TRUE;
	}

	dterror.clear ();
	return B_FALSE;
}
Exemple #4
0
char *
DmxMsg::getHeaders (DtMailBoolean abbreviated_only)
{
    DtMailEnv		error;
    DtMail::Session	*m_session = theRoamApp.session()->session(); 
    DtMail::MailRc	*mail_rc = m_session->mailRc(error);
    DtMail::Envelope	*env = message->getEnvelope(error);

    DtMailHeaderHandle	hdr_hnd;
    char		*name;
    DtMailValueSeq	value;

    // Code from MsgScrollingList - display_message().
    // We're trying to reduce heap size by not allocating and 
    // deleting space in every loop iteration.  So just have a 
    // fixed size buffer initially.
    // 

    // Initial line size.  When not enough, allocate more.
    int			buffer_size = 2048;   
    char		*buffer = new char [buffer_size];
    int			count = 0;
    int			hdr_num = 0;
    char		*newline = "\n";
    char		*separator = ": ";
    int			val = 0;

    //
    // Iterate through each header in the message and add it
    // to the buffer.
    //
    for (hdr_hnd = env->getFirstHeader(error, &name, value), *buffer = '\0';
	 hdr_hnd && !error.isSet();
	 hdr_hnd = env->getNextHeader(error, hdr_hnd, &name, value), hdr_num++)
    {
        if (abbreviated_only == DTM_TRUE &&
	    (hdr_num != 0 || strcmp(name, "From") != 0))
	{
	    DtMailEnv ierror;
	    if (mail_rc->ignore(ierror, name))
	    {
		free(name);
		value.clear();
		continue;
	    }
	}
	    
	for (val=0;  val<value.length();  val++)
	  count += strlen(name) +
		   strlen(*(value[val])) +
		   strlen(separator) +
		   strlen(newline) + 1;

	if (count > buffer_size)
	{
	    // Need to increase buffer size.
	    char	*new_buffer;
	    
	    buffer_size *= 2;
	    new_buffer = new char [buffer_size];
	    memset(new_buffer, 0, buffer_size);

	    strcpy(new_buffer, buffer);
	    delete [] buffer;
	    buffer = new_buffer;
	}

	for (val=0;  val<value.length();  val++)
	{
	    strcat(buffer, name);
		
	    if (hdr_num != 0 || strcmp(name, "From") != 0)
	      strcat(buffer, separator);
	    else
	      strcat(buffer, " ");
		
	    strcat(buffer, *(value[val]));
	    strcat(buffer, newline);
	}
	value.clear();
	free(name);
    }

    //
    // Need to free this after using;
    //
    return buffer;
}
Exemple #5
0
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);
}
Exemple #6
0
DtMail::Session::Session(DtMailEnv & error, const char * app_name)
: _events(16), _valid_keys(2048)
{
    _DtMutex = MutexInit();

    error.clear();

    _object_signature = 0;
    _cur_key = 0;

    // Create the ToolTalk session for managing file locking,
    // if one doesn't exist.
    _tt_channel = tt_default_procid();
    if (tt_pointer_error(_tt_channel) != TT_OK) {
	_tt_channel = ttdt_open(&_tt_fd, app_name, "SunSoft", "%I", 0);
	if (tt_pointer_error(_tt_channel) != TT_OK) {
	    error.setError(DTME_TTFailure);
	    DebugPrintf(1,
			"DtMail::createSession - ttdt_open returns %s\n",
			tt_status_message(tt_pointer_error(_tt_channel)));
	    return;
	}
    }
    else {
	_tt_fd = tt_fd();
    }

    // The event_fd is how we allow async behavior to occur in a
    // compatible way. We use a Unix domain socket as the file descriptor.
    // The client will watch for activity on this file descriptor, and
    // call our event routine when there is activity (either from XtMainLoop,
    // or through some other method).
    //
    pipe(_event_fd);

    _app_name = strdup(app_name);

    DtMailEnv b_error;

    _mail_rc = new MailRc(error, this);

    buildImplTable(error);
    if (error.isSet()) {
	return;
    }

    _obj_mutex = MutexInit();

    // The default implementation is specified via the DEFAULT_BACKEND
    // variable. If this is not set in the .mailrc, then choose entry
    // zero.
    //
    const char * value;
    _mail_rc->getValue(b_error, "DEFAULT_BACKEND", &value);
    if (b_error.isNotSet()) {
	_default_impl = lookupImpl(value);
	if (_default_impl < 0) {
	    _default_impl = 0;
	}
    }
    else {
	b_error.clear();
	_default_impl = 0;
    }

    DtMailSigChldList = new DtVirtArray<SigChldInfo *>(8);

    _busy_cb = NULL;
    _busy_cb_data = NULL;
    _canAutoSave = DTM_TRUE;

    _object_signature = SessionSignature;

    return;
}
Exemple #7
0
void
AttachArea::parseAttachments(
    DtMailEnv &mail_error,
    DtMail::Message* msg,
    Boolean empty,
    int startBP
)
{
    DtMail::BodyPart * tmpBP;
    int index = 1;
    int num_attachments = 0;
    char * name;


    // First unmanage and empty out the current contents.

    // SMD sets this boolean to FALSE so that previous message's attachments
    // are not cleared.  E.g. Including/forwarding multiple messages each
    // with attachments.
    // RMW sets this boolean to TRUE so that all attachments are cleared in
    // the attachment pane everytime a new message is displayed.

    if ( empty ) {

	// First unmanage the clipWindow.
	// Unmanaging the attachment pane is visually ugly

	XtUnmanageChild(_clipWindow);
	this->clearAttachArea();
    }

    _deleteCount = 0;

    // Now fill list with new attachments.

    tmpBP = msg->getFirstBodyPart(mail_error);
    if (mail_error.isSet()) {
	// do something
    }

    // Sync up the index with the bodyPart from which to begin
    // adding attachments into attachPane.
    // 
    while (startBP > index) {
	tmpBP = msg->getNextBodyPart(mail_error, tmpBP);
	index++;
    }
    
    while (tmpBP != NULL) {
	num_attachments++;
	tmpBP->getContents(
			mail_error,
			NULL,
			NULL,
			NULL,
			&name,
			NULL,
			NULL);
	
	if (mail_error.isSet()) {
	    // do something
	}

	// It is possible for an attachment to not have a name.
	if (!name) {
	    name = "NoName";
	}

	this->addAttachment(name, tmpBP);
	tmpBP = msg->getNextBodyPart(mail_error, tmpBP);
	if (mail_error.isSet()) {
	    // do something
	}

	free(name);
    }
}