/*---------------------------------------------------------------------- handle hang up signal -- SIGUSR2 Not much to do. Rely on periodic mail file check pointing. ----------------------------------------------------------------------*/ static RETSIGTYPE usr2_signal(int sig) { char c, *mbox, mboxbuf[20]; int i; MAILSTREAM *stream; NETMBX mb; for(i = 0; i < ps_global->s_pool.nstream; i++) { stream = ps_global->s_pool.streams[i]; if(stream && sp_flagged(stream, SP_LOCKED) && !sp_dead_stream(stream) && !stream->lock && !stream->rdonly && stream->mailbox && (c = *stream->mailbox) != '{' && c != '*') { pine_mail_check(stream); /* write latest state */ stream->rdonly = 1; /* and become read-only */ (void) pine_mail_ping(stream); mbox = stream->mailbox; if(!strucmp(stream->mailbox, ps_global->inbox_name) || !strcmp(stream->mailbox, ps_global->VAR_INBOX_PATH) || !strucmp(stream->original_mailbox, ps_global->inbox_name) || !strcmp(stream->original_mailbox, ps_global->VAR_INBOX_PATH)) mbox = "INBOX"; else if(mail_valid_net_parse(stream->mailbox, &mb) && mb.mailbox) mbox = mb.mailbox; q_status_message1(SM_ASYNC, 3, 7, _("Another email program is accessing %s. Session now Read-Only."), short_str((mbox && *mbox) ? mbox : "folder", mboxbuf, sizeof(mboxbuf), 19, FrontDots)); dprint((1, "** folder %s went read-only **\n\n", stream->mailbox)); } } }
long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body) { RFC822BUFFER buf; char tmp[SENDBUFLEN+1]; long error = NIL; long retry = NIL; buf.f = smtp_soutr; /* initialize buffer */ buf.s = stream->netstream; buf.end = (buf.beg = buf.cur = tmp) + SENDBUFLEN; tmp[SENDBUFLEN] = '\0'; /* must have additional null guard byte */ if (!(env->to || env->cc || env->bcc)) { /* no recipients in request */ smtp_seterror (stream,SMTPHARDERROR,"No recipients specified"); return NIL; } do { /* make sure stream is in good shape */ if (retry) { /* need to retry with authentication? */ NETMBX mb; /* yes, build remote name for authentication */ sprintf (tmp,"{%.200s/smtp%s}<none>", (long) mail_parameters (NIL,GET_TRUSTDNS,NIL) ? ((long) mail_parameters (NIL,GET_SASLUSESPTRNAME,NIL) ? net_remotehost (stream->netstream) : net_host (stream->netstream)) : stream->host, (stream->netstream->dtb == (NETDRIVER *) mail_parameters (NIL,GET_SSLDRIVER,NIL)) ? "/ssl" : ""); mail_valid_net_parse (tmp,&mb); smtp_send (stream,"RSET",NIL); if (!smtp_auth (stream,&mb,tmp)) return NIL; retry = NIL; /* no retry at this point */ } strcpy (tmp,"FROM:<"); /* compose "MAIL FROM:<return-path>" */ #ifdef RFC2821 if (env->return_path && env->return_path->host && !((strlen (env->return_path->mailbox) > SMTPMAXLOCALPART) || (strlen (env->return_path->host) > SMTPMAXDOMAIN))) { rfc822_cat (tmp,env->return_path->mailbox,NIL); sprintf (tmp + strlen (tmp),"@%s",env->return_path->host); } #else /* old code with A-D-L support */ if (env->return_path && env->return_path->host && !((env->return_path->adl && (strlen (env->return_path->adl) > SMTPMAXPATH)) || (strlen (env->return_path->mailbox) > SMTPMAXLOCALPART) || (strlen (env->return_path->host) > SMTPMAXDOMAIN))) rfc822_address (tmp,env->return_path); #endif strcat (tmp,">"); if (ESMTP.ok) { if (ESMTP.eightbit.ok && ESMTP.eightbit.want) strcat (tmp," BODY=8BITMIME"); if (ESMTP.dsn.ok && ESMTP.dsn.want) { strcat (tmp,ESMTP.dsn.full ? " RET=FULL" : " RET=HDRS"); if (ESMTP.dsn.envid) sprintf (tmp + strlen (tmp)," ENVID=%.100s",ESMTP.dsn.envid); } } /* send "MAIL FROM" command */ switch (smtp_send (stream,type,tmp)) { case SMTPUNAVAIL: /* mailbox unavailable? */ case SMTPWANTAUTH: /* wants authentication? */ case SMTPWANTAUTH2: if (ESMTP.auth) retry = T;/* yes, retry with authentication */ case SMTPOK: /* looks good */ break; default: /* other failure */ smtp_send (stream,"RSET",NIL); return NIL; } /* negotiate the recipients */ if (!retry && env->to) retry = smtp_rcpt (stream,env->to,&error); if (!retry && env->cc) retry = smtp_rcpt (stream,env->cc,&error); if (!retry && env->bcc) retry = smtp_rcpt (stream,env->bcc,&error); if (!retry && error) { /* any recipients failed? */ smtp_send (stream,"RSET",NIL); smtp_seterror (stream,SMTPHARDERROR,"One or more recipients failed"); return NIL; } } while (retry); /* negotiate data command */ if (!(smtp_send (stream,"DATA",NIL) == SMTPREADY)) { smtp_send (stream,"RSET",NIL); return NIL; } /* send message data */ if (!rfc822_output_full (&buf,env,body, ESMTP.eightbit.ok && ESMTP.eightbit.want)) { smtp_fake (stream,"SMTP connection broken (message data)"); return NIL; /* can't do much else here */ } /* send trailing dot */ if (smtp_send (stream,".",NIL) != SMTPOK) { smtp_send (stream,"RSET",NIL); return NIL; } return LONGT; }