NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
smtp.c
Go to the documentation of this file.
1
28
34
35/* This file contains code for direct SMTP delivery of email messages. */
36
37#include "config.h"
38#include <arpa/inet.h>
39#include <netdb.h>
40#include <stdbool.h>
41#include <stdint.h>
42#include <stdio.h>
43#include <unistd.h>
44#include "mutt/lib.h"
45#include "address/lib.h"
46#include "config/lib.h"
47#include "email/lib.h"
48#include "core/lib.h"
49#include "conn/lib.h"
50#include "smtp.h"
51#include "progress/lib.h"
52#include "question/lib.h"
53#include "globals.h"
54#include "mutt_socket.h"
55#include "sendlib.h"
56#ifdef USE_SASL_GNU
57#include <gsasl.h>
58#endif
59#ifdef USE_SASL_CYRUS
60#include <sasl/sasl.h>
61#endif
62
64#define smtp_success(x) (((x) / 100) == 2)
65#define SMTP_READY 334
66#define SMTP_CONTINUE 354
67
68#define SMTP_ERR_READ -2
69#define SMTP_ERR_WRITE -3
70#define SMTP_ERR_CODE -4
71
72#define SMTP_PORT 25
73#define SMTPS_PORT 465
74
75#define SMTP_AUTH_SUCCESS 0
76#define SMTP_AUTH_UNAVAIL 1
77#define SMTP_AUTH_FAIL -1
78
79// clang-format off
83typedef uint8_t SmtpCapFlags;
84#define SMTP_CAP_NO_FLAGS 0
85#define SMTP_CAP_STARTTLS (1 << 0)
86#define SMTP_CAP_AUTH (1 << 1)
87#define SMTP_CAP_DSN (1 << 2)
88#define SMTP_CAP_EIGHTBITMIME (1 << 3)
89#define SMTP_CAP_SMTPUTF8 (1 << 4)
90#define SMTP_CAP_ALL ((1 << 5) - 1)
91// clang-format on
92
97{
98 const char *auth_mechs;
100 struct Connection *conn;
102 const char *fqdn;
103};
104
109{
118 int (*authenticate)(struct SmtpAccountData *adata, const char *method);
119
120 const char *method;
122};
123
130static bool valid_smtp_code(char *buf, int *n)
131{
132 return (mutt_str_atoi(buf, n) - buf) <= 3;
133}
134
141static int smtp_get_resp(struct SmtpAccountData *adata)
142{
143 int n;
144 char buf[1024] = { 0 };
145
146 do
147 {
148 n = mutt_socket_readln(buf, sizeof(buf), adata->conn);
149 if (n < 4)
150 {
151 /* read error, or no response code */
152 return SMTP_ERR_READ;
153 }
154 const char *s = buf + 4; /* Skip the response code and the space/dash */
155 size_t plen;
156
157 if (mutt_istr_startswith(s, "8BITMIME"))
158 {
160 }
161 else if ((plen = mutt_istr_startswith(s, "AUTH ")))
162 {
163 adata->capabilities |= SMTP_CAP_AUTH;
164 FREE(&adata->auth_mechs);
165 adata->auth_mechs = mutt_str_dup(s + plen);
166 }
167 else if (mutt_istr_startswith(s, "DSN"))
168 {
169 adata->capabilities |= SMTP_CAP_DSN;
170 }
171 else if (mutt_istr_startswith(s, "STARTTLS"))
172 {
174 }
175 else if (mutt_istr_startswith(s, "SMTPUTF8"))
176 {
178 }
179
180 if (!valid_smtp_code(buf, &n))
181 return SMTP_ERR_CODE;
182
183 } while (buf[3] == '-');
184
185 if (smtp_success(n) || (n == SMTP_CONTINUE))
186 return 0;
187
188 mutt_error(_("SMTP session failed: %s"), buf);
189 return -1;
190}
191
199static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
200{
201 if (!al)
202 return 0;
203
204 const char *const c_dsn_notify = cs_subset_string(adata->sub, "dsn_notify");
205
206 struct Address *a = NULL;
207 TAILQ_FOREACH(a, al, entries)
208 {
209 /* weed out group mailboxes, since those are for display only */
210 if (!a->mailbox || a->group)
211 {
212 continue;
213 }
214 char buf[1024] = { 0 };
215 if ((adata->capabilities & SMTP_CAP_DSN) && c_dsn_notify)
216 {
217 snprintf(buf, sizeof(buf), "RCPT TO:<%s> NOTIFY=%s\r\n",
218 buf_string(a->mailbox), c_dsn_notify);
219 }
220 else
221 {
222 snprintf(buf, sizeof(buf), "RCPT TO:<%s>\r\n", buf_string(a->mailbox));
223 }
224 if (mutt_socket_send(adata->conn, buf) == -1)
225 return SMTP_ERR_WRITE;
226 int rc = smtp_get_resp(adata);
227 if (rc != 0)
228 return rc;
229 }
230
231 return 0;
232}
233
241static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
242{
243 char buf[1024] = { 0 };
244 struct Progress *progress = NULL;
245 int rc = SMTP_ERR_WRITE;
246 int term = 0;
247 size_t buflen = 0;
248
249 FILE *fp = mutt_file_fopen(msgfile, "r");
250 if (!fp)
251 {
252 mutt_error(_("SMTP session failed: unable to open %s"), msgfile);
253 return -1;
254 }
255 const long size = mutt_file_get_size_fp(fp);
256 if (size == 0)
257 {
258 mutt_file_fclose(&fp);
259 return -1;
260 }
261 unlink(msgfile);
262 progress = progress_new(MUTT_PROGRESS_NET, size);
263 progress_set_message(progress, _("Sending message..."));
264
265 snprintf(buf, sizeof(buf), "DATA\r\n");
266 if (mutt_socket_send(adata->conn, buf) == -1)
267 {
268 mutt_file_fclose(&fp);
269 goto done;
270 }
271 rc = smtp_get_resp(adata);
272 if (rc != 0)
273 {
274 mutt_file_fclose(&fp);
275 goto done;
276 }
277
278 rc = SMTP_ERR_WRITE;
279 while (fgets(buf, sizeof(buf) - 1, fp))
280 {
281 buflen = mutt_str_len(buf);
282 term = buflen && buf[buflen - 1] == '\n';
283 if (term && ((buflen == 1) || (buf[buflen - 2] != '\r')))
284 snprintf(buf + buflen - 1, sizeof(buf) - buflen + 1, "\r\n");
285 if (buf[0] == '.')
286 {
287 if (mutt_socket_send_d(adata->conn, ".", MUTT_SOCK_LOG_FULL) == -1)
288 {
289 mutt_file_fclose(&fp);
290 goto done;
291 }
292 }
293 if (mutt_socket_send_d(adata->conn, buf, MUTT_SOCK_LOG_FULL) == -1)
294 {
295 mutt_file_fclose(&fp);
296 goto done;
297 }
298 progress_update(progress, MAX(0, ftell(fp)), -1);
299 }
300 if (!term && buflen &&
301 (mutt_socket_send_d(adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) == -1))
302 {
303 mutt_file_fclose(&fp);
304 goto done;
305 }
306 mutt_file_fclose(&fp);
307
308 /* terminate the message body */
309 if (mutt_socket_send(adata->conn, ".\r\n") == -1)
310 goto done;
311
312 rc = smtp_get_resp(adata);
313
314done:
315 progress_free(&progress);
316 return rc;
317}
318
322static const char *smtp_get_field(enum ConnAccountField field, void *gf_data)
323{
324 struct SmtpAccountData *adata = gf_data;
325 if (!adata)
326 return NULL;
327
328 switch (field)
329 {
330 case MUTT_CA_LOGIN:
331 case MUTT_CA_USER:
332 {
333 const char *const c_smtp_user = cs_subset_string(adata->sub, "smtp_user");
334 return c_smtp_user;
335 }
336 case MUTT_CA_PASS:
337 {
338 const char *const c_smtp_pass = cs_subset_string(adata->sub, "smtp_pass");
339 return c_smtp_pass;
340 }
342 {
343 const char *const c_smtp_oauth_refresh_command = cs_subset_string(adata->sub, "smtp_oauth_refresh_command");
344 return c_smtp_oauth_refresh_command;
345 }
346 case MUTT_CA_HOST:
347 default:
348 return NULL;
349 }
350}
351
359static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
360{
361 cac->flags = 0;
362 cac->port = 0;
364 cac->service = "smtp";
366 cac->gf_data = adata;
367
368 const char *const c_smtp_url = cs_subset_string(adata->sub, "smtp_url");
369
370 struct Url *url = url_parse(c_smtp_url);
371 if (!url || ((url->scheme != U_SMTP) && (url->scheme != U_SMTPS)) ||
372 !url->host || (account_from_url(cac, url) < 0))
373 {
374 url_free(&url);
375 mutt_error(_("Invalid SMTP URL: %s"), c_smtp_url);
376 return -1;
377 }
378
379 if (url->scheme == U_SMTPS)
380 cac->flags |= MUTT_ACCT_SSL;
381
382 if (cac->port == 0)
383 {
384 if (cac->flags & MUTT_ACCT_SSL)
385 {
386 cac->port = SMTPS_PORT;
387 }
388 else
389 {
390 static unsigned short SmtpPort = 0;
391 if (SmtpPort == 0)
392 {
393 struct servent *service = getservbyname("smtp", "tcp");
394 if (service)
395 SmtpPort = ntohs(service->s_port);
396 else
397 SmtpPort = SMTP_PORT;
398 mutt_debug(LL_DEBUG3, "Using default SMTP port %d\n", SmtpPort);
399 }
400 cac->port = SmtpPort;
401 }
402 }
403
404 url_free(&url);
405 return 0;
406}
407
415static int smtp_helo(struct SmtpAccountData *adata, bool esmtp)
416{
418
419 if (!esmtp)
420 {
421 /* if TLS or AUTH are requested, use EHLO */
422 if (adata->conn->account.flags & MUTT_ACCT_USER)
423 esmtp = true;
424#ifdef USE_SSL
425 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
426 const enum QuadOption c_ssl_starttls = cs_subset_quad(adata->sub, "ssl_starttls");
427
428 if (c_ssl_force_tls || (c_ssl_starttls != MUTT_NO))
429 esmtp = true;
430#endif
431 }
432
433 char buf[1024] = { 0 };
434 snprintf(buf, sizeof(buf), "%s %s\r\n", esmtp ? "EHLO" : "HELO", adata->fqdn);
435 /* XXX there should probably be a wrapper in mutt_socket.c that
436 * repeatedly calls adata->conn->write until all data is sent. This
437 * currently doesn't check for a short write. */
438 if (mutt_socket_send(adata->conn, buf) == -1)
439 return SMTP_ERR_WRITE;
440 return smtp_get_resp(adata);
441}
442
443#if defined(USE_SASL_CYRUS) || defined(USE_SASL_GNU)
450static int smtp_code(const struct Buffer *buf, int *n)
451{
452 if (buf_len(buf) < 3)
453 return false;
454
455 char code[4] = { 0 };
456 const char *str = buf_string(buf);
457
458 code[0] = str[0];
459 code[1] = str[1];
460 code[2] = str[2];
461 code[3] = 0;
462
463 const char *end = mutt_str_atoi(code, n);
464 if (!end || (*end != '\0'))
465 return false;
466 return true;
467}
468
480static int smtp_get_auth_response(struct Connection *conn, struct Buffer *input_buf,
481 int *smtp_rc, struct Buffer *response_buf)
482{
483 buf_reset(response_buf);
484 do
485 {
486 if (mutt_socket_buffer_readln(input_buf, conn) < 0)
487 return -1;
488 if (!smtp_code(input_buf, smtp_rc))
489 {
490 return -1;
491 }
492
493 if (*smtp_rc != SMTP_READY)
494 break;
495
496 const char *smtp_response = input_buf->data + 3;
497 if (*smtp_response)
498 {
499 smtp_response++;
500 buf_addstr(response_buf, smtp_response);
501 }
502 } while (buf_at(input_buf, 3) == '-');
503
504 return 0;
505}
506#endif
507
508#ifdef USE_SASL_GNU
516static int smtp_auth_gsasl(struct SmtpAccountData *adata, const char *mechlist)
517{
518 Gsasl_session *gsasl_session = NULL;
519 struct Buffer *input_buf = NULL, *output_buf = NULL, *smtp_response_buf = NULL;
520 int rc = SMTP_AUTH_FAIL, gsasl_rc = GSASL_OK, smtp_rc;
521
522 const char *chosen_mech = mutt_gsasl_get_mech(mechlist, adata->auth_mechs);
523 if (!chosen_mech)
524 {
525 mutt_debug(LL_DEBUG2, "returned no usable mech\n");
526 return SMTP_AUTH_UNAVAIL;
527 }
528
529 mutt_debug(LL_DEBUG2, "using mech %s\n", chosen_mech);
530
531 if (mutt_gsasl_client_new(adata->conn, chosen_mech, &gsasl_session) < 0)
532 {
533 mutt_debug(LL_DEBUG1, "Error allocating GSASL connection\n");
534 return SMTP_AUTH_UNAVAIL;
535 }
536
537 if (OptGui)
538 mutt_message(_("Authenticating (%s)..."), chosen_mech);
539
540 input_buf = buf_pool_get();
541 output_buf = buf_pool_get();
542 smtp_response_buf = buf_pool_get();
543
544 buf_printf(output_buf, "AUTH %s", chosen_mech);
545
546 /* Work around broken SMTP servers. See Debian #1010658.
547 * The msmtp source also forces IR for PLAIN because the author
548 * encountered difficulties with a server requiring it. */
549 if (mutt_str_equal(chosen_mech, "PLAIN"))
550 {
551 char *gsasl_step_output = NULL;
552 gsasl_rc = gsasl_step64(gsasl_session, "", &gsasl_step_output);
553 if (gsasl_rc != GSASL_NEEDS_MORE && gsasl_rc != GSASL_OK)
554 {
555 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
556 gsasl_strerror(gsasl_rc));
557 goto fail;
558 }
559
560 buf_addch(output_buf, ' ');
561 buf_addstr(output_buf, gsasl_step_output);
562 gsasl_free(gsasl_step_output);
563 }
564
565 buf_addstr(output_buf, "\r\n");
566
567 do
568 {
569 if (mutt_socket_send(adata->conn, buf_string(output_buf)) < 0)
570 goto fail;
571
572 if (smtp_get_auth_response(adata->conn, input_buf, &smtp_rc, smtp_response_buf) < 0)
573 goto fail;
574
575 if (smtp_rc != SMTP_READY)
576 break;
577
578 char *gsasl_step_output = NULL;
579 gsasl_rc = gsasl_step64(gsasl_session, buf_string(smtp_response_buf), &gsasl_step_output);
580 if ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK))
581 {
582 buf_strcpy(output_buf, gsasl_step_output);
583 buf_addstr(output_buf, "\r\n");
584 gsasl_free(gsasl_step_output);
585 }
586 else
587 {
588 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
589 gsasl_strerror(gsasl_rc));
590 }
591 } while ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK));
592
593 if (smtp_rc == SMTP_READY)
594 {
595 mutt_socket_send(adata->conn, "*\r\n");
596 goto fail;
597 }
598
599 if (smtp_success(smtp_rc) && (gsasl_rc == GSASL_OK))
601
602fail:
603 buf_pool_release(&input_buf);
604 buf_pool_release(&output_buf);
605 buf_pool_release(&smtp_response_buf);
606 mutt_gsasl_client_finish(&gsasl_session);
607
608 if (rc == SMTP_AUTH_FAIL)
609 mutt_debug(LL_DEBUG2, "%s failed\n", chosen_mech);
610
611 return rc;
612}
613#endif
614
615#ifdef USE_SASL_CYRUS
623static int smtp_auth_sasl(struct SmtpAccountData *adata, const char *mechlist)
624{
625 sasl_conn_t *saslconn = NULL;
626 sasl_interact_t *interaction = NULL;
627 const char *mech = NULL;
628 const char *data = NULL;
629 unsigned int data_len = 0;
630 struct Buffer *temp_buf = NULL;
631 struct Buffer *output_buf = NULL;
632 struct Buffer *smtp_response_buf = NULL;
633 int rc = SMTP_AUTH_FAIL;
634 int rc_sasl;
635 int rc_smtp;
636
637 if (mutt_sasl_client_new(adata->conn, &saslconn) < 0)
638 return SMTP_AUTH_FAIL;
639
640 /* Perform SASL client handshake: start negotiation with the server,
641 * handling any interactive prompts from the SASL library */
642 do
643 {
644 rc_sasl = sasl_client_start(saslconn, mechlist, &interaction, &data, &data_len, &mech);
645 if (rc_sasl == SASL_INTERACT)
646 mutt_sasl_interact(interaction);
647 } while (rc_sasl == SASL_INTERACT);
648
649 if ((rc_sasl != SASL_OK) && (rc_sasl != SASL_CONTINUE))
650 {
651 mutt_debug(LL_DEBUG2, "%s unavailable\n", NONULL(mech));
652 sasl_dispose(&saslconn);
653 return SMTP_AUTH_UNAVAIL;
654 }
655
656 if (OptGui)
657 {
658 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
659 mutt_message(_("Authenticating (%s)..."), mech);
660 }
661
662 /* Build the initial AUTH command, optionally including the first
663 * base64-encoded SASL response as part of the AUTH line */
664 temp_buf = buf_pool_get();
665 output_buf = buf_pool_get();
666 smtp_response_buf = buf_pool_get();
667
668 buf_printf(output_buf, "AUTH %s", mech);
669 if (data_len > 0)
670 {
671 buf_addch(output_buf, ' ');
672 mutt_b64_buffer_encode(temp_buf, data, data_len);
673 buf_addstr(output_buf, buf_string(temp_buf));
674 }
675 buf_addstr(output_buf, "\r\n");
676
677 /* Main SASL challenge/response loop: send base64-encoded data to the
678 * server, decode its response, and pass it to sasl_client_step() */
679 do
680 {
681 if (mutt_socket_send(adata->conn, buf_string(output_buf)) < 0)
682 goto fail;
683
684 if (smtp_get_auth_response(adata->conn, temp_buf, &rc_smtp, smtp_response_buf) < 0)
685 goto fail;
686
687 if (rc_smtp != SMTP_READY)
688 break;
689
690 if (mutt_b64_buffer_decode(temp_buf, buf_string(smtp_response_buf)) < 0)
691 {
692 mutt_debug(LL_DEBUG1, "error base64-decoding server response\n");
693 goto fail;
694 }
695
696 do
697 {
698 rc_sasl = sasl_client_step(saslconn, buf_string(temp_buf), buf_len(temp_buf),
699 &interaction, &data, &data_len);
700 if (rc_sasl == SASL_INTERACT)
701 mutt_sasl_interact(interaction);
702 } while (rc_sasl == SASL_INTERACT);
703
704 if (data_len > 0)
705 mutt_b64_buffer_encode(output_buf, data, data_len);
706 else
707 buf_reset(output_buf);
708
709 buf_addstr(output_buf, "\r\n");
710 } while (rc_sasl != SASL_FAIL);
711
712 /* Check final SMTP result and set up SASL security layer on success */
713 if (smtp_success(rc_smtp))
714 {
715 mutt_sasl_setup_conn(adata->conn, saslconn);
717 }
718 else
719 {
720 if (rc_smtp == SMTP_READY)
721 mutt_socket_send(adata->conn, "*\r\n");
722 sasl_dispose(&saslconn);
723 }
724
725fail:
726 buf_pool_release(&temp_buf);
727 buf_pool_release(&output_buf);
728 buf_pool_release(&smtp_response_buf);
729 return rc;
730}
731#endif
732
740static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
741{
742 /* If they did not explicitly request or configure oauth then fail quietly */
743 const char *const c_smtp_oauth_refresh_command = cs_subset_string(NeoMutt->sub, "smtp_oauth_refresh_command");
744 if (!method && !c_smtp_oauth_refresh_command)
745 return SMTP_AUTH_UNAVAIL;
746
747 const char *authtype = xoauth2 ? "XOAUTH2" : "OAUTHBEARER";
748
749 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
750 mutt_message(_("Authenticating (%s)..."), authtype);
751
752 /* We get the access token from the smtp_oauth_refresh_command */
753 char *oauthbearer = mutt_account_getoauthbearer(&adata->conn->account, xoauth2);
754 if (!oauthbearer)
755 return SMTP_AUTH_FAIL;
756
757 char *ibuf = NULL;
758 mutt_str_asprintf(&ibuf, "AUTH %s %s\r\n", authtype, oauthbearer);
759
760 int rc = mutt_socket_send(adata->conn, ibuf);
761 FREE(&oauthbearer);
762 FREE(&ibuf);
763
764 if (rc == -1)
765 return SMTP_AUTH_FAIL;
766 if (smtp_get_resp(adata) != 0)
767 return SMTP_AUTH_FAIL;
768
769 return SMTP_AUTH_SUCCESS;
770}
771
778static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
779{
780 return smtp_auth_oauth_xoauth2(adata, method, false);
781}
782
789static int smtp_auth_xoauth2(struct SmtpAccountData *adata, const char *method)
790{
791 return smtp_auth_oauth_xoauth2(adata, method, true);
792}
793
803static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
804{
805 struct Buffer *buf = NULL;
806 struct ConnAccount *cac = &adata->conn->account;
807 int rc = -1;
808
809 /* Get username and password. Bail out of any can't be retrieved. */
810 if ((mutt_account_getuser(cac) < 0) || (mutt_account_getpass(cac) < 0))
811 goto error;
812
813 /* Build the initial client response. */
814 buf = buf_pool_get();
815 mutt_sasl_plain_msg(buf, "AUTH PLAIN", cac->user, cac->user, cac->pass);
816 buf_add_printf(buf, "\r\n");
817
818 /* Send request, receive response (with a check for OK code). */
819 if ((mutt_socket_send(adata->conn, buf_string(buf)) < 0) || smtp_get_resp(adata))
820 goto error;
821
822 rc = 0; // Auth was successful
823
824error:
825 if (rc != 0)
826 {
827 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
828 mutt_error(_("%s authentication failed"), "SASL");
829 }
830 buf_pool_release(&buf);
831 return rc;
832}
833
843static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
844{
845 char b64[1024] = { 0 };
846 char buf[1026] = { 0 };
847
848 /* Get username and password. Bail out of any can't be retrieved. */
849 if ((mutt_account_getuser(&adata->conn->account) < 0) ||
850 (mutt_account_getpass(&adata->conn->account) < 0))
851 {
852 goto error;
853 }
854
855 /* Send the AUTH LOGIN request. */
856 if (mutt_socket_send(adata->conn, "AUTH LOGIN\r\n") < 0)
857 {
858 goto error;
859 }
860
861 /* Read the 334 VXNlcm5hbWU6 challenge ("Username:" base64-encoded) */
862 int rc = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
863 if ((rc < 0) || !mutt_str_equal(buf, "334 VXNlcm5hbWU6"))
864 {
865 goto error;
866 }
867
868 /* Send the username */
869 size_t len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.user);
870 mutt_b64_encode(buf, len, b64, sizeof(b64));
871 snprintf(buf, sizeof(buf), "%s\r\n", b64);
872 if (mutt_socket_send(adata->conn, buf) < 0)
873 {
874 goto error;
875 }
876
877 /* Read the 334 UGFzc3dvcmQ6 challenge ("Password:" base64-encoded) */
878 rc = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
879 if ((rc < 0) || !mutt_str_equal(buf, "334 UGFzc3dvcmQ6"))
880 {
881 goto error;
882 }
883
884 /* Send the password */
885 len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.pass);
886 mutt_b64_encode(buf, len, b64, sizeof(b64));
887 snprintf(buf, sizeof(buf), "%s\r\n", b64);
888 if (mutt_socket_send(adata->conn, buf) < 0)
889 {
890 goto error;
891 }
892
893 /* Check the final response */
894 if (smtp_get_resp(adata) < 0)
895 {
896 goto error;
897 }
898
899 /* If we got here, auth was successful. */
900 return 0;
901
902error:
903 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
904 mutt_error(_("%s authentication failed"), "LOGIN");
905 return -1;
906}
907
911static const struct SmtpAuth SmtpAuthenticators[] = {
912 // clang-format off
913 { smtp_auth_oauth, "oauthbearer" },
914 { smtp_auth_xoauth2, "xoauth2" },
915 { smtp_auth_plain, "plain" },
916 { smtp_auth_login, "login" },
917#ifdef USE_SASL_CYRUS
918 { smtp_auth_sasl, NULL },
919#endif
920#ifdef USE_SASL_GNU
921 { smtp_auth_gsasl, NULL },
922#endif
923 // clang-format on
924};
925
934bool smtp_auth_is_valid(const char *authenticator)
935{
936 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
937 {
938 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
939 if (auth->method && mutt_istr_equal(auth->method, authenticator))
940 return true;
941 }
942
943 return false;
944}
945
952static int smtp_authenticate(struct SmtpAccountData *adata)
953{
954 int r = SMTP_AUTH_UNAVAIL;
955
956 const struct Slist *c_smtp_authenticators = cs_subset_slist(adata->sub, "smtp_authenticators");
957 if (c_smtp_authenticators && (c_smtp_authenticators->count > 0))
958 {
959 mutt_debug(LL_DEBUG2, "Trying user-defined smtp_authenticators\n");
960
961 /* Try user-specified list of authentication methods */
962 struct ListNode *np = NULL;
963 STAILQ_FOREACH(np, &c_smtp_authenticators->head, entries)
964 {
965 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
966
967 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
968 {
969 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
970 if (!auth->method || mutt_istr_equal(auth->method, np->data))
971 {
972 r = auth->authenticate(adata, np->data);
973 if (r == SMTP_AUTH_SUCCESS)
974 return r;
975 }
976 }
977 }
978 }
979 else
980 {
981 /* Fall back to default: any authenticator */
982#if defined(USE_SASL_CYRUS)
983 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_sasl, if using sasl\n");
984 r = smtp_auth_sasl(adata, adata->auth_mechs);
985#elif defined(USE_SASL_GNU)
986 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_gsasl, if using gsasl\n");
987 r = smtp_auth_gsasl(adata, adata->auth_mechs);
988#else
989 mutt_debug(LL_DEBUG2, "Falling back to using any authenticator available\n");
990 /* Try all available authentication methods */
991 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
992 {
993 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
994 mutt_debug(LL_DEBUG2, "Trying method %s\n", auth->method ? auth->method : "<variable>");
995 r = auth->authenticate(adata, auth->method);
996 if (r == SMTP_AUTH_SUCCESS)
997 return r;
998 }
999#endif
1000 }
1001
1002 if (r != SMTP_AUTH_SUCCESS)
1004
1005 if (r == SMTP_AUTH_FAIL)
1006 {
1007 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
1008 mutt_error(_("%s authentication failed"), "SASL");
1009 }
1010 else if (r == SMTP_AUTH_UNAVAIL)
1011 {
1012 mutt_error(_("No authenticators available"));
1013 }
1014
1015 return (r == SMTP_AUTH_SUCCESS) ? 0 : -1;
1016}
1017
1025static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
1026{
1027 int rc;
1028
1029 if (mutt_socket_open(adata->conn))
1030 return -1;
1031
1032 const bool force_auth = cs_subset_string(adata->sub, "smtp_user");
1033 esmtp |= force_auth;
1034
1035 /* get greeting string */
1036 rc = smtp_get_resp(adata);
1037 if (rc != 0)
1038 return rc;
1039
1040 rc = smtp_helo(adata, esmtp);
1041 if (rc != 0)
1042 return rc;
1043
1044#ifdef USE_SSL
1045 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
1046 enum QuadOption ans = MUTT_NO;
1047 if (adata->conn->ssf != 0)
1048 ans = MUTT_NO;
1049 else if (c_ssl_force_tls)
1050 ans = MUTT_YES;
1051 else if ((adata->capabilities & SMTP_CAP_STARTTLS) &&
1052 ((ans = query_quadoption(_("Secure connection with TLS?"),
1053 adata->sub, "ssl_starttls")) == MUTT_ABORT))
1054 {
1055 return -1;
1056 }
1057
1058 if (ans == MUTT_YES)
1059 {
1060 if (mutt_socket_send(adata->conn, "STARTTLS\r\n") < 0)
1061 return SMTP_ERR_WRITE;
1062 rc = smtp_get_resp(adata);
1063 // Clear any data after the STARTTLS acknowledgement
1064 mutt_socket_empty(adata->conn);
1065 if (rc != 0)
1066 return rc;
1067
1068 if (mutt_ssl_starttls(adata->conn))
1069 {
1070 mutt_error(_("Could not negotiate TLS connection"));
1071 return -1;
1072 }
1073
1074 /* re-EHLO to get authentication mechanisms */
1075 rc = smtp_helo(adata, esmtp);
1076 if (rc != 0)
1077 return rc;
1078 }
1079#endif
1080
1081 if (force_auth || adata->conn->account.flags & MUTT_ACCT_USER)
1082 {
1083 if (!(adata->capabilities & SMTP_CAP_AUTH))
1084 {
1085 mutt_error(_("SMTP server does not support authentication"));
1086 return -1;
1087 }
1088
1089 return smtp_authenticate(adata);
1090 }
1091
1092 return 0;
1093}
1094
1107int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to,
1108 const struct AddressList *cc, const struct AddressList *bcc,
1109 const char *msgfile, bool eightbit, struct ConfigSubset *sub)
1110{
1111 struct SmtpAccountData adata = { 0 };
1112 struct ConnAccount cac = { { 0 } };
1113 const char *envfrom = NULL;
1114 int rc = -1;
1115
1116 adata.sub = sub;
1117 adata.fqdn = mutt_fqdn(false, adata.sub);
1118 if (!adata.fqdn)
1119 adata.fqdn = NONULL(ShortHostname);
1120
1121 const struct Address *c_envelope_from_address = cs_subset_address(adata.sub, "envelope_from_address");
1122
1123 if (smtp_fill_account(&adata, &cac) < 0)
1124 return rc;
1125
1126 adata.conn = mutt_conn_find(&cac);
1127 if (!adata.conn)
1128 return -1;
1129
1130 /* it might be better to synthesize an envelope from from user and host
1131 * but this condition is most likely arrived at accidentally */
1132 if (c_envelope_from_address)
1133 {
1134 envfrom = buf_string(c_envelope_from_address->mailbox);
1135 }
1136 else if (from && !TAILQ_EMPTY(from))
1137 {
1138 envfrom = buf_string(TAILQ_FIRST(from)->mailbox);
1139 }
1140 else
1141 {
1142 mutt_error(_("No from address given"));
1143 mutt_socket_close(adata.conn);
1144 return -1;
1145 }
1146
1147 const char *const c_dsn_return = cs_subset_string(adata.sub, "dsn_return");
1148
1149 struct Buffer *buf = buf_pool_get();
1150 do
1151 {
1152 /* send our greeting */
1153 rc = smtp_open(&adata, eightbit);
1154 if (rc != 0)
1155 break;
1156 FREE(&adata.auth_mechs);
1157
1158 /* send the sender's address */
1159 buf_printf(buf, "MAIL FROM:<%s>", envfrom);
1160 if (eightbit && (adata.capabilities & SMTP_CAP_EIGHTBITMIME))
1161 buf_addstr(buf, " BODY=8BITMIME");
1162
1163 if (c_dsn_return && (adata.capabilities & SMTP_CAP_DSN))
1164 buf_add_printf(buf, " RET=%s", c_dsn_return);
1165
1166 if ((adata.capabilities & SMTP_CAP_SMTPUTF8) &&
1169 {
1170 buf_addstr(buf, " SMTPUTF8");
1171 }
1172 buf_addstr(buf, "\r\n");
1173 if (mutt_socket_send(adata.conn, buf_string(buf)) == -1)
1174 {
1175 rc = SMTP_ERR_WRITE;
1176 break;
1177 }
1178 rc = smtp_get_resp(&adata);
1179 if (rc != 0)
1180 break;
1181
1182 /* send the recipient list */
1183 if ((rc = smtp_rcpt_to(&adata, to)) || (rc = smtp_rcpt_to(&adata, cc)) ||
1184 (rc = smtp_rcpt_to(&adata, bcc)))
1185 {
1186 break;
1187 }
1188
1189 /* send the message data */
1190 rc = smtp_data(&adata, msgfile);
1191 if (rc != 0)
1192 break;
1193
1194 mutt_socket_send(adata.conn, "QUIT\r\n");
1195
1196 rc = 0;
1197 } while (false);
1198
1199 mutt_socket_close(adata.conn);
1200 FREE(&adata.conn);
1201 FREE(&adata.auth_mechs);
1202
1203 if (rc == SMTP_ERR_READ)
1204 mutt_error(_("SMTP session failed: read error"));
1205 else if (rc == SMTP_ERR_WRITE)
1206 mutt_error(_("SMTP session failed: write error"));
1207 else if (rc == SMTP_ERR_CODE)
1208 mutt_error(_("Invalid server response"));
1209
1210 buf_pool_release(&buf);
1211 return rc;
1212}
bool mutt_addrlist_uses_unicode(const struct AddressList *al)
Do any of a list of addresses use Unicode characters.
Definition address.c:1531
bool mutt_addr_uses_unicode(const char *str)
Does this address use Unicode character.
Definition address.c:1511
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Email Address Handling.
const char * mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition atoi.c:191
size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen)
Convert raw bytes to a base64 string.
Definition base64.c:148
size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len)
Convert raw bytes to NUL-terminated base64 string.
Definition base64.c:243
int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
Convert NUL-terminated base64 string to raw bytes.
Definition base64.c:261
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:668
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition helpers.c:242
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition helpers.c:192
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
Convenience wrapper for the config headers.
Connection Library.
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition connaccount.c:51
void mutt_account_unsetpass(struct ConnAccount *cac)
Unset ConnAccount's password.
char * mutt_account_getoauthbearer(struct ConnAccount *cac, bool xoauth2)
Get an OAUTHBEARER/XOAUTH2 token.
ConnAccountField
Login credentials.
Definition connaccount.h:33
@ MUTT_CA_OAUTH_CMD
OAuth refresh command.
Definition connaccount.h:38
@ MUTT_CA_USER
User name.
Definition connaccount.h:36
@ MUTT_CA_LOGIN
Login name.
Definition connaccount.h:35
@ MUTT_CA_HOST
Server name.
Definition connaccount.h:34
@ MUTT_CA_PASS
Password.
Definition connaccount.h:37
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition connaccount.h:47
#define MUTT_ACCT_USER
User field has been set.
Definition connaccount.h:44
Convenience wrapper for the core headers.
Structs that make up an email.
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition file.c:1432
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
char * ShortHostname
Short version of the hostname.
Definition globals.c:36
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:48
Global variables.
int mutt_ssl_starttls(struct Connection *conn)
Negotiate TLS over an already opened connection.
Definition gnutls.c:1172
static const char * smtp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition smtp.c:322
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int smtp_auth_xoauth2(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection using XOAUTH2 - Implements SmtpAuth::authenticate() -.
Definition smtp.c:789
static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text - Implements SmtpAuth::authenticate() -.
Definition smtp.c:843
static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text - Implements SmtpAuth::authenticate() -.
Definition smtp.c:803
static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection using OAUTHBEARER - Implements SmtpAuth::authenticate() -.
Definition smtp.c:778
const char * mutt_gsasl_get_mech(const char *requested_mech, const char *server_mechlist)
Pick a connection mechanism.
Definition gsasl.c:164
int mutt_gsasl_client_new(struct Connection *conn, const char *mech, Gsasl_session **sctx)
Create a new GNU SASL client.
Definition gsasl.c:199
void mutt_gsasl_client_finish(Gsasl_session **sctx)
Free a GNU SASL client.
Definition gsasl.c:220
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define countof(x)
Definition memory.h:49
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:677
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition string.c:808
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:503
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition string.c:246
int account_from_url(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
@ MUTT_ACCT_TYPE_SMTP
Smtp Account.
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition mutt_socket.c:88
NeoMutt connections.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
Progress Bar.
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition lib.h:83
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition progress.c:139
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition progress.c:110
void progress_set_message(struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition progress.c:80
QuadOption
Possible values for a quad-option.
Definition quad.h:36
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
Definition quad.h:37
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition quad.h:38
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
Ask the user a question.
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
Definition question.c:384
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define TAILQ_FIRST(head)
Definition queue.h:780
#define TAILQ_EMPTY(head)
Definition queue.h:778
int mutt_sasl_interact(sasl_interact_t *interaction)
Perform an SASL interaction with the user.
Definition sasl.c:699
int mutt_sasl_client_new(struct Connection *conn, sasl_conn_t **saslconn)
Wrapper for sasl_client_new()
Definition sasl.c:601
void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn)
Set up an SASL connection.
Definition sasl.c:736
size_t mutt_sasl_plain_msg(struct Buffer *buf, const char *cmd, const char *authz, const char *user, const char *pass)
Construct a base64 encoded SASL PLAIN message.
Definition sasl_plain.c:50
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition sendlib.c:713
Miscellaneous functions for sending an email.
static int smtp_get_resp(struct SmtpAccountData *adata)
Read a command response from the SMTP server.
Definition smtp.c:141
#define SMTPS_PORT
Default SMTPS (SMTP over SSL) port.
Definition smtp.c:73
#define SMTP_CAP_NO_FLAGS
No flags are set.
Definition smtp.c:84
#define SMTP_CAP_STARTTLS
Server supports STARTTLS command.
Definition smtp.c:85
uint8_t SmtpCapFlags
SMTP server capabilities.
Definition smtp.c:83
static int smtp_authenticate(struct SmtpAccountData *adata)
Authenticate to an SMTP server.
Definition smtp.c:952
#define SMTP_ERR_READ
Error reading from server.
Definition smtp.c:68
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition smtp.c:934
static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
Authenticate an SMTP connection using OAUTHBEARER/XOAUTH2.
Definition smtp.c:740
static const struct SmtpAuth SmtpAuthenticators[]
Accepted authentication methods.
Definition smtp.c:911
static bool valid_smtp_code(char *buf, int *n)
Is the is a valid SMTP return code?
Definition smtp.c:130
#define SMTP_AUTH_UNAVAIL
Authentication method unavailable.
Definition smtp.c:76
static int smtp_helo(struct SmtpAccountData *adata, bool esmtp)
Say hello to an SMTP Server.
Definition smtp.c:415
#define SMTP_ERR_CODE
Invalid server response code.
Definition smtp.c:70
#define SMTP_CAP_EIGHTBITMIME
Server supports 8-bit MIME content.
Definition smtp.c:88
#define smtp_success(x)
Check if SMTP response code indicates success (2xx codes)
Definition smtp.c:64
#define SMTP_AUTH_FAIL
Authentication failed.
Definition smtp.c:77
#define SMTP_CAP_AUTH
Server supports AUTH command.
Definition smtp.c:86
static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
Send data to an SMTP server.
Definition smtp.c:241
#define SMTP_ERR_WRITE
Error writing to server.
Definition smtp.c:69
static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
Create ConnAccount object from SMTP Url.
Definition smtp.c:359
#define SMTP_AUTH_SUCCESS
Authentication completed successfully.
Definition smtp.c:75
#define SMTP_CAP_SMTPUTF8
Server accepts UTF-8 strings.
Definition smtp.c:89
#define SMTP_CONTINUE
SMTP server ready to accept message data.
Definition smtp.c:66
int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to, const struct AddressList *cc, const struct AddressList *bcc, const char *msgfile, bool eightbit, struct ConfigSubset *sub)
Send a message using SMTP.
Definition smtp.c:1107
#define SMTP_CAP_DSN
Server supports Delivery Status Notification.
Definition smtp.c:87
static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
Set the recipient to an Address.
Definition smtp.c:199
static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
Open an SMTP Connection.
Definition smtp.c:1025
#define SMTP_PORT
Default SMTP port.
Definition smtp.c:72
#define SMTP_READY
SMTP server ready for authentication data.
Definition smtp.c:65
Send email to an SMTP server.
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition socket.c:100
void mutt_socket_empty(struct Connection *conn)
Clear out any queued data.
Definition socket.c:306
int mutt_socket_open(struct Connection *conn)
Simple wrapper.
Definition socket.c:76
int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int dbg)
Read a line from a socket.
Definition socket.c:238
#define MUTT_SOCK_LOG_FULL
Log everything including full protocol.
Definition socket.h:53
#define mutt_socket_readln(buf, buflen, conn)
Definition socket.h:55
#define mutt_socket_send(conn, buf)
Definition socket.h:56
#define mutt_socket_buffer_readln(buf, conn)
Definition socket.h:60
#define mutt_socket_send_d(conn, buf, dbg)
Definition socket.h:57
#define NONULL(x)
Definition string2.h:44
An email address.
Definition address.h:35
bool group
Group mailbox?
Definition address.h:38
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
String manipulation buffer.
Definition buffer.h:36
char * data
Pointer to data.
Definition buffer.h:37
A set of inherited config items.
Definition subset.h:46
Login details for a remote server.
Definition connaccount.h:53
char user[128]
Username.
Definition connaccount.h:56
char pass[256]
Password.
Definition connaccount.h:57
const char * service
Name of the service, e.g. "imap".
Definition connaccount.h:61
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition connaccount.h:70
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition connaccount.h:59
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition connaccount.h:60
void * gf_data
Private data to pass to get_field()
Definition connaccount.h:72
unsigned short port
Port to connect to.
Definition connaccount.h:58
unsigned int ssf
Security strength factor, in bits (see notes)
Definition connection.h:50
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
String list.
Definition slist.h:37
struct ListHead head
List containing values.
Definition slist.h:38
size_t count
Number of values in list.
Definition slist.h:39
Server connection data.
Definition smtp.c:97
const char * fqdn
Fully-qualified domain name.
Definition smtp.c:102
struct ConfigSubset * sub
Config scope.
Definition smtp.c:101
struct Connection * conn
Server Connection.
Definition smtp.c:100
const char * auth_mechs
Allowed authorisation mechanisms.
Definition smtp.c:98
SmtpCapFlags capabilities
Server capabilities.
Definition smtp.c:99
SMTP authentication multiplexor.
Definition smtp.c:109
int(* authenticate)(struct SmtpAccountData *adata, const char *method)
Definition smtp.c:118
const char * method
Name of authentication method supported, NULL means variable.
Definition smtp.c:120
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition url.h:69
char * host
Host.
Definition url.h:73
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition url.h:70
struct Url * url_parse(const char *src)
Fill in Url.
Definition url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition url.c:124
@ U_SMTPS
Url is smtps://.
Definition url.h:44
@ U_SMTP
Url is smtp://.
Definition url.h:43