int mu_url_aget_param (const mu_url_t url, const char *param, char **val) { const char *s; int status = mu_url_sget_param (url, param, &s); if (status == 0) { *val = strdup (s); if (!*val) status = ENOMEM; } return status; }
static int pop_open (mu_mailbox_t mbox, int flags) { struct _pop3_mailbox *mpd = mbox->data; int status; mu_stream_t stream; struct mu_sockaddr *sa; struct mu_sockaddr_hints hints; /* Sanity checks. */ if (mpd == NULL) return EINVAL; mbox->flags = flags; memset (&hints, 0, sizeof (hints)); hints.flags = MU_AH_DETECT_FAMILY; hints.port = mpd->pops ? MU_POPS_PORT : MU_POP_PORT; hints.protocol = IPPROTO_TCP; hints.socktype = SOCK_STREAM; status = mu_sockaddr_from_url (&sa, mbox->url, &hints); if (status) return status; status = mu_tcp_stream_create_from_sa (&stream, sa, NULL, mbox->flags); if (status) { mu_sockaddr_free (sa); return status; } #ifdef WITH_TLS if (mpd->pops) { mu_stream_t newstr; status = mu_tls_client_stream_create (&newstr, stream, stream, 0); mu_stream_unref (stream); if (status) { mu_error ("pop_open: mu_tls_client_stream_create: %s", mu_strerror (status)); return status; } stream = newstr; } #endif /* WITH_TLS */ /* FIXME: How to configure buffer size? */ mu_stream_set_buffer (stream, mu_buffer_line, 0); status = mu_pop3_create (&mpd->pop3); if (status) { mu_stream_destroy (&stream); return status; } mu_pop3_set_carrier (mpd->pop3, stream); if (mu_debug_level_p (MU_DEBCAT_MAILBOX, MU_DEBUG_PROT)) mu_pop3_trace (mpd->pop3, MU_POP3_TRACE_SET); if (mu_debug_level_p (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE6)) mu_pop3_trace_mask (mpd->pop3, MU_POP3_TRACE_SET, MU_XSCRIPT_SECURE); if (mu_debug_level_p (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE7)) mu_pop3_trace_mask (mpd->pop3, MU_POP3_TRACE_SET, MU_XSCRIPT_PAYLOAD); do { status = mu_pop3_connect (mpd->pop3); if (status) break; status = mu_pop3_capa (mpd->pop3, 1, NULL); if (status == MU_ERR_REPLY) { mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR, ("server rejected the CAPA command: %s", mu_pop3_strresp (mpd->pop3))); /* try to continue anyway */ } else if (status) return status; #ifdef WITH_TLS if (!mpd->pops && mu_url_sget_param (mbox->url, "notls", NULL) == MU_ERR_NOENT && mu_pop3_capa_test (mpd->pop3, "STLS", NULL) == 0) { status = mu_pop3_stls (mpd->pop3); if (status) break; } #endif status = mu_authority_authenticate (mbox->folder->authority); } while (0); if (status) mu_pop3_destroy (&mpd->pop3); return status; }