text stringlengths 0 357 |
|---|
dc_smtp_t* dc_smtp_new(dc_context_t* context) |
{ |
dc_smtp_t* smtp = NULL; |
if ((smtp=calloc(1, sizeof(dc_smtp_t)))==NULL) { |
exit(29); |
} |
smtp->log_connect_errors = 1; |
smtp->context = context; /* should be used for logging only */ |
return smtp; |
} |
void dc_smtp_unref(dc_smtp_t* smtp) |
{ |
if (smtp==NULL) { |
return; |
} |
dc_smtp_disconnect(smtp); |
free(smtp->from); |
free(smtp->error); |
free(smtp); |
} |
static void log_error(dc_smtp_t* smtp, const char* what_failed, int r) |
{ |
char* error_msg = dc_mprintf("%s: %s: %s", what_failed, mailsmtp_strerror(r), smtp->etpan->response); |
dc_log_warning(smtp->context, 0, "%s", error_msg); |
free(smtp->error); |
smtp->error = error_msg; |
smtp->error_etpan = r; |
} |
int dc_smtp_is_connected(const dc_smtp_t* smtp) |
{ |
return (smtp && smtp->etpan)? 1 : 0; |
} |
static void body_progress(size_t current, size_t maximum, void* user_data) |
{ |
#if DEBUG_SMTP |
printf("body_progress called with current=%i, maximum=%i.", (int)current, (int)maximum); |
#endif |
} |
#if DEBUG_SMTP |
static void logger(mailsmtp* smtp, int log_type, const char* buffer__, size_t size, void* user_data) |
{ |
char* buffer = malloc(size+1); |
memcpy(buffer, buffer__, size); |
buffer[size] = 0; |
printf("SMTP: %i: %s", log_type, buffer__); |
} |
#endif |
int dc_smtp_connect(dc_smtp_t* smtp, const dc_loginparam_t* lp) |
{ |
int success = 0; |
int r = 0; |
int try_esmtp = 0; |
if (smtp==NULL || lp==NULL) { |
return 0; |
} |
if (smtp->etpan) { |
dc_log_warning(smtp->context, 0, "SMTP already connected."); |
success = 1; /* otherwise, the handle would get deleted */ |
goto cleanup; |
} |
if (lp->addr==NULL || lp->send_server==NULL || lp->send_port==0) { |
dc_log_event_seq(smtp->context, DC_EVENT_ERROR_NETWORK, &smtp->log_connect_errors, |
"SMTP bad parameters."); |
goto cleanup; |
} |
free(smtp->from); |
smtp->from = dc_strdup(lp->addr); |
smtp->etpan = mailsmtp_new(0, NULL); |
if (smtp->etpan==NULL) { |
dc_log_error(smtp->context, 0, "SMTP-object creation failed."); |
goto cleanup; |
} |
mailsmtp_set_timeout(smtp->etpan, DC_SMTP_TIMEOUT_SEC); |
mailsmtp_set_progress_callback(smtp->etpan, body_progress, smtp); |
#if DEBUG_SMTP |
mailsmtp_set_logger(smtp->etpan, logger, smtp); |
#endif |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.