text
stringlengths
0
357
if (r != MAILSMTP_NO_ERROR)
{
dc_log_event_seq(smtp->context, DC_EVENT_ERROR_NETWORK, &smtp->log_connect_errors,
"SMTP-login failed for user %s (%s)", lp->send_user, mailsmtp_strerror(r));
goto cleanup;
}
dc_log_event(smtp->context, DC_EVENT_SMTP_CONNECTED, 0,
"SMTP-login as %s ok.", lp->send_user);
}
success = 1;
cleanup:
if (!success) {
if (smtp->etpan) {
mailsmtp_free(smtp->etpan);
smtp->etpan = NULL;
}
}
return success;
}
void dc_smtp_disconnect(dc_smtp_t* smtp)
{
if (smtp==NULL) {
return;
}
if (smtp->etpan) {
//mailsmtp_quit(smtp->etpan); -- ?
mailsmtp_free(smtp->etpan);
smtp->etpan = NULL;
}
}
/*******************************************************************************
* Send a message
******************************************************************************/
int dc_smtp_send_msg(dc_smtp_t* smtp, const clist* recipients, const char* data_not_terminated, size_t data_bytes)
{
int success = 0;
int r = 0;
clistiter* iter = NULL;
if (smtp==NULL) {
goto cleanup;
}
if (recipients==NULL || clist_count(recipients)==0 || data_not_terminated==NULL || data_bytes==0) {
success = 1;
goto cleanup; // "null message" send
}
if (smtp->etpan==NULL) {
goto cleanup;
}
// set source
// the `etPanSMTPTest` is the ENVID from RFC 3461 (SMTP DSNs), we should probably replace it by a random value
if ((r=(smtp->esmtp?
mailesmtp_mail(smtp->etpan, smtp->from, 1, "etPanSMTPTest") :
mailsmtp_mail(smtp->etpan, smtp->from))) != MAILSMTP_NO_ERROR)
{
// this error is very usual - we've simply lost the server connection and reconnect as soon as possible.
// log_error() does log the error as a warning in the first place, the caller will log the error later if it is not recovered.
log_error(smtp, "SMTP failed to start message", r);
goto cleanup;
}
// set recipients
// if the recipient is on the same server, this may fail at once.
// TODO: question is what to do if one recipient in a group fails
for (iter=clist_begin(recipients); iter!=NULL; iter=clist_next(iter)) {
const char* rcpt = clist_content(iter);
if ((r = (smtp->esmtp?
mailesmtp_rcpt(smtp->etpan, rcpt, MAILSMTP_DSN_NOTIFY_FAILURE|MAILSMTP_DSN_NOTIFY_DELAY, NULL) :
mailsmtp_rcpt(smtp->etpan, rcpt))) != MAILSMTP_NO_ERROR) {
log_error(smtp, "SMTP failed to add recipient", r);
goto cleanup;
}
}
// message
if ((r = mailsmtp_data(smtp->etpan)) != MAILSMTP_NO_ERROR) {
log_error(smtp, "SMTP failed to set data", r);
goto cleanup;
}
if ((r = mailsmtp_data_message(smtp->etpan, data_not_terminated, data_bytes)) != MAILSMTP_NO_ERROR) {
log_error(smtp, "SMTP failed to send message", r);
goto cleanup;
}