NeoMutt  2023-03-22
Teaching an old dog new tricks
DOXYGEN
smtp.c
Go to the documentation of this file.
1
31/* This file contains code for direct SMTP delivery of email messages. */
32
33#include "config.h"
34#include <arpa/inet.h>
35#include <netdb.h>
36#include <stdbool.h>
37#include <stdint.h>
38#include <stdio.h>
39#include <string.h>
40#include <unistd.h>
41#include "mutt/lib.h"
42#include "address/lib.h"
43#include "config/lib.h"
44#include "email/lib.h"
45#include "conn/lib.h"
46#include "smtp.h"
47#include "lib.h"
48#include "progress/lib.h"
49#include "question/lib.h"
50#include "globals.h" // IWYU pragma: keep
51#include "mutt_account.h"
52#include "mutt_socket.h"
53#ifdef USE_SASL_GNU
54#include <gsasl.h>
55#endif
56#ifdef USE_SASL_CYRUS
57#include <sasl/sasl.h>
58#include <sasl/saslutil.h>
59#endif
60
61#define smtp_success(x) ((x) / 100 == 2)
62#define SMTP_READY 334
63#define SMTP_CONTINUE 354
64
65#define SMTP_ERR_READ -2
66#define SMTP_ERR_WRITE -3
67#define SMTP_ERR_CODE -4
68
69#define SMTP_PORT 25
70#define SMTPS_PORT 465
71
72#define SMTP_AUTH_SUCCESS 0
73#define SMTP_AUTH_UNAVAIL 1
74#define SMTP_AUTH_FAIL -1
75
76// clang-format off
80typedef uint8_t SmtpCapFlags;
81#define SMTP_CAP_NO_FLAGS 0
82#define SMTP_CAP_STARTTLS (1 << 0)
83#define SMTP_CAP_AUTH (1 << 1)
84#define SMTP_CAP_DSN (1 << 2)
85#define SMTP_CAP_EIGHTBITMIME (1 << 3)
86#define SMTP_CAP_SMTPUTF8 (1 << 4)
87
88#define SMTP_CAP_ALL ((1 << 5) - 1)
89// clang-format on
90
95{
96 const char *auth_mechs;
98 struct Connection *conn;
99 struct ConfigSubset *sub;
100 const char *fqdn;
101};
102
107{
114 int (*authenticate)(struct SmtpAccountData *adata, const char *method);
115
116 const char *method;
118};
119
127static bool valid_smtp_code(char *buf, size_t buflen, int *n)
128{
129 return (mutt_str_atoi(buf, n) - buf) <= 3;
130}
131
138static int smtp_get_resp(struct SmtpAccountData *adata)
139{
140 int n;
141 char buf[1024] = { 0 };
142
143 do
144 {
145 n = mutt_socket_readln(buf, sizeof(buf), adata->conn);
146 if (n < 4)
147 {
148 /* read error, or no response code */
149 return SMTP_ERR_READ;
150 }
151 const char *s = buf + 4; /* Skip the response code and the space/dash */
152 size_t plen;
153
154 if (mutt_istr_startswith(s, "8BITMIME"))
156 else if ((plen = mutt_istr_startswith(s, "AUTH ")))
157 {
158 adata->capabilities |= SMTP_CAP_AUTH;
159 FREE(&adata->auth_mechs);
160 adata->auth_mechs = mutt_str_dup(s + plen);
161 }
162 else if (mutt_istr_startswith(s, "DSN"))
163 adata->capabilities |= SMTP_CAP_DSN;
164 else if (mutt_istr_startswith(s, "STARTTLS"))
166 else if (mutt_istr_startswith(s, "SMTPUTF8"))
168
169 if (!valid_smtp_code(buf, n, &n))
170 return SMTP_ERR_CODE;
171
172 } while (buf[3] == '-');
173
174 if (smtp_success(n) || (n == SMTP_CONTINUE))
175 return 0;
176
177 mutt_error(_("SMTP session failed: %s"), buf);
178 return -1;
179}
180
188static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
189{
190 if (!al)
191 return 0;
192
193 const char *const c_dsn_notify = cs_subset_string(adata->sub, "dsn_notify");
194
195 struct Address *a = NULL;
196 TAILQ_FOREACH(a, al, entries)
197 {
198 /* weed out group mailboxes, since those are for display only */
199 if (!a->mailbox || a->group)
200 {
201 continue;
202 }
203 char buf[1024] = { 0 };
204 if ((adata->capabilities & SMTP_CAP_DSN) && c_dsn_notify)
205 snprintf(buf, sizeof(buf), "RCPT TO:<%s> NOTIFY=%s\r\n", a->mailbox, c_dsn_notify);
206 else
207 snprintf(buf, sizeof(buf), "RCPT TO:<%s>\r\n", a->mailbox);
208 if (mutt_socket_send(adata->conn, buf) == -1)
209 return SMTP_ERR_WRITE;
210 int rc = smtp_get_resp(adata);
211 if (rc != 0)
212 return rc;
213 }
214
215 return 0;
216}
217
225static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
226{
227 char buf[1024] = { 0 };
228 struct Progress *progress = NULL;
229 int rc = SMTP_ERR_WRITE;
230 int term = 0;
231 size_t buflen = 0;
232
233 FILE *fp = fopen(msgfile, "r");
234 if (!fp)
235 {
236 mutt_error(_("SMTP session failed: unable to open %s"), msgfile);
237 return -1;
238 }
239 const long size = mutt_file_get_size_fp(fp);
240 if (size == 0)
241 {
242 mutt_file_fclose(&fp);
243 return -1;
244 }
245 unlink(msgfile);
246 progress = progress_new(_("Sending message..."), MUTT_PROGRESS_NET, size);
247
248 snprintf(buf, sizeof(buf), "DATA\r\n");
249 if (mutt_socket_send(adata->conn, buf) == -1)
250 {
251 mutt_file_fclose(&fp);
252 goto done;
253 }
254 rc = smtp_get_resp(adata);
255 if (rc != 0)
256 {
257 mutt_file_fclose(&fp);
258 goto done;
259 }
260
261 rc = SMTP_ERR_WRITE;
262 while (fgets(buf, sizeof(buf) - 1, fp))
263 {
264 buflen = mutt_str_len(buf);
265 term = buflen && buf[buflen - 1] == '\n';
266 if (term && ((buflen == 1) || (buf[buflen - 2] != '\r')))
267 snprintf(buf + buflen - 1, sizeof(buf) - buflen + 1, "\r\n");
268 if (buf[0] == '.')
269 {
270 if (mutt_socket_send_d(adata->conn, ".", MUTT_SOCK_LOG_FULL) == -1)
271 {
272 mutt_file_fclose(&fp);
273 goto done;
274 }
275 }
276 if (mutt_socket_send_d(adata->conn, buf, MUTT_SOCK_LOG_FULL) == -1)
277 {
278 mutt_file_fclose(&fp);
279 goto done;
280 }
281 progress_update(progress, MAX(0, ftell(fp)), -1);
282 }
283 if (!term && buflen &&
284 (mutt_socket_send_d(adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) == -1))
285 {
286 mutt_file_fclose(&fp);
287 goto done;
288 }
289 mutt_file_fclose(&fp);
290
291 /* terminate the message body */
292 if (mutt_socket_send(adata->conn, ".\r\n") == -1)
293 goto done;
294
295 rc = smtp_get_resp(adata);
296
297done:
298 progress_free(&progress);
299 return rc;
300}
301
305static const char *smtp_get_field(enum ConnAccountField field, void *gf_data)
306{
307 struct SmtpAccountData *adata = gf_data;
308 if (!adata)
309 return NULL;
310
311 switch (field)
312 {
313 case MUTT_CA_LOGIN:
314 case MUTT_CA_USER:
315 {
316 const char *const c_smtp_user = cs_subset_string(adata->sub, "smtp_user");
317 return c_smtp_user;
318 }
319 case MUTT_CA_PASS:
320 {
321 const char *const c_smtp_pass = cs_subset_string(adata->sub, "smtp_pass");
322 return c_smtp_pass;
323 }
325 {
326 const char *const c_smtp_oauth_refresh_command = cs_subset_string(adata->sub, "smtp_oauth_refresh_command");
327 return c_smtp_oauth_refresh_command;
328 }
329 case MUTT_CA_HOST:
330 default:
331 return NULL;
332 }
333}
334
342static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
343{
344 cac->flags = 0;
345 cac->port = 0;
347 cac->service = "smtp";
349 cac->gf_data = adata;
350
351 const char *const c_smtp_url = cs_subset_string(adata->sub, "smtp_url");
352
353 struct Url *url = url_parse(c_smtp_url);
354 if (!url || ((url->scheme != U_SMTP) && (url->scheme != U_SMTPS)) ||
355 !url->host || (mutt_account_fromurl(cac, url) < 0))
356 {
357 url_free(&url);
358 mutt_error(_("Invalid SMTP URL: %s"), c_smtp_url);
359 return -1;
360 }
361
362 if (url->scheme == U_SMTPS)
363 cac->flags |= MUTT_ACCT_SSL;
364
365 if (cac->port == 0)
366 {
367 if (cac->flags & MUTT_ACCT_SSL)
368 cac->port = SMTPS_PORT;
369 else
370 {
371 static unsigned short SmtpPort = 0;
372 if (SmtpPort == 0)
373 {
374 struct servent *service = getservbyname("smtp", "tcp");
375 if (service)
376 SmtpPort = ntohs(service->s_port);
377 else
378 SmtpPort = SMTP_PORT;
379 mutt_debug(LL_DEBUG3, "Using default SMTP port %d\n", SmtpPort);
380 }
381 cac->port = SmtpPort;
382 }
383 }
384
385 url_free(&url);
386 return 0;
387}
388
396static int smtp_helo(struct SmtpAccountData *adata, bool esmtp)
397{
399
400 if (!esmtp)
401 {
402 /* if TLS or AUTH are requested, use EHLO */
403 if (adata->conn->account.flags & MUTT_ACCT_USER)
404 esmtp = true;
405#ifdef USE_SSL
406 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
407 const enum QuadOption c_ssl_starttls = cs_subset_quad(adata->sub, "ssl_starttls");
408
409 if (c_ssl_force_tls || (c_ssl_starttls != MUTT_NO))
410 esmtp = true;
411#endif
412 }
413
414 char buf[1024] = { 0 };
415 snprintf(buf, sizeof(buf), "%s %s\r\n", esmtp ? "EHLO" : "HELO", adata->fqdn);
416 /* XXX there should probably be a wrapper in mutt_socket.c that
417 * repeatedly calls adata->conn->write until all data is sent. This
418 * currently doesn't check for a short write. */
419 if (mutt_socket_send(adata->conn, buf) == -1)
420 return SMTP_ERR_WRITE;
421 return smtp_get_resp(adata);
422}
423
424#ifdef USE_SASL_GNU
437static int smtp_code(const char *str, size_t len, int *n)
438{
439 char code[4];
440
441 if (len < 4)
442 return false;
443 code[0] = str[0];
444 code[1] = str[1];
445 code[2] = str[2];
446 code[3] = 0;
447
448 const char *end = mutt_str_atoi(code, n);
449 if (!end || (*end != '\0'))
450 return false;
451 return true;
452}
453
465static int smtp_get_auth_response(struct Connection *conn, struct Buffer *input_buf,
466 int *smtp_rc, struct Buffer *response_buf)
467{
468 mutt_buffer_reset(response_buf);
469 do
470 {
471 if (mutt_socket_buffer_readln(input_buf, conn) < 0)
472 return -1;
473 if (!smtp_code(mutt_buffer_string(input_buf),
474 mutt_buffer_len(input_buf) + 1 /* number of bytes */, smtp_rc))
475 {
476 return -1;
477 }
478
479 if (*smtp_rc != SMTP_READY)
480 break;
481
482 const char *smtp_response = mutt_buffer_string(input_buf) + 3;
483 if (*smtp_response)
484 {
485 smtp_response++;
486 mutt_buffer_addstr(response_buf, smtp_response);
487 }
488 } while (mutt_buffer_string(input_buf)[3] == '-');
489
490 return 0;
491}
492
500static int smtp_auth_gsasl(struct SmtpAccountData *adata, const char *mechlist)
501{
502 Gsasl_session *gsasl_session = NULL;
503 struct Buffer *input_buf = NULL, *output_buf = NULL, *smtp_response_buf = NULL;
504 int rc = SMTP_AUTH_FAIL, gsasl_rc = GSASL_OK, smtp_rc;
505
506 const char *chosen_mech = mutt_gsasl_get_mech(mechlist, adata->auth_mechs);
507 if (!chosen_mech)
508 {
509 mutt_debug(LL_DEBUG2, "returned no usable mech\n");
510 return SMTP_AUTH_UNAVAIL;
511 }
512
513 mutt_debug(LL_DEBUG2, "using mech %s\n", chosen_mech);
514
515 if (mutt_gsasl_client_new(adata->conn, chosen_mech, &gsasl_session) < 0)
516 {
517 mutt_debug(LL_DEBUG1, "Error allocating GSASL connection.\n");
518 return SMTP_AUTH_UNAVAIL;
519 }
520
521 if (!OptNoCurses)
522 mutt_message(_("Authenticating (%s)..."), chosen_mech);
523
524 input_buf = mutt_buffer_pool_get();
525 output_buf = mutt_buffer_pool_get();
526 smtp_response_buf = mutt_buffer_pool_get();
527
528 mutt_buffer_printf(output_buf, "AUTH %s", chosen_mech);
529
530 /* Work around broken SMTP servers. See Debian #1010658.
531 * The msmtp source also forces IR for PLAIN because the author
532 * encountered difficulties with a server requiring it. */
533 if (mutt_str_equal(chosen_mech, "PLAIN"))
534 {
535 char *gsasl_step_output = NULL;
536 gsasl_rc = gsasl_step64(gsasl_session, "", &gsasl_step_output);
537 if (gsasl_rc != GSASL_NEEDS_MORE && gsasl_rc != GSASL_OK)
538 {
539 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
540 gsasl_strerror(gsasl_rc));
541 goto fail;
542 }
543
544 mutt_buffer_addch(output_buf, ' ');
545 mutt_buffer_addstr(output_buf, gsasl_step_output);
546 gsasl_free(gsasl_step_output);
547 }
548
549 mutt_buffer_addstr(output_buf, "\r\n");
550
551 do
552 {
553 if (mutt_socket_send(adata->conn, mutt_buffer_string(output_buf)) < 0)
554 goto fail;
555
556 if (smtp_get_auth_response(adata->conn, input_buf, &smtp_rc, smtp_response_buf) < 0)
557 goto fail;
558
559 if (smtp_rc != SMTP_READY)
560 break;
561
562 char *gsasl_step_output = NULL;
563 gsasl_rc = gsasl_step64(gsasl_session, mutt_buffer_string(smtp_response_buf),
564 &gsasl_step_output);
565 if ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK))
566 {
567 mutt_buffer_strcpy(output_buf, gsasl_step_output);
568 mutt_buffer_addstr(output_buf, "\r\n");
569 gsasl_free(gsasl_step_output);
570 }
571 else
572 {
573 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
574 gsasl_strerror(gsasl_rc));
575 }
576 } while ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK));
577
578 if (smtp_rc == SMTP_READY)
579 {
580 mutt_socket_send(adata->conn, "*\r\n");
581 goto fail;
582 }
583
584 if (smtp_success(smtp_rc) && (gsasl_rc == GSASL_OK))
586
587fail:
588 mutt_buffer_pool_release(&input_buf);
589 mutt_buffer_pool_release(&output_buf);
590 mutt_buffer_pool_release(&smtp_response_buf);
591 mutt_gsasl_client_finish(&gsasl_session);
592
593 if (rc == SMTP_AUTH_FAIL)
594 mutt_debug(LL_DEBUG2, "%s failed\n", chosen_mech);
595
596 return rc;
597}
598#endif
599
600#ifdef USE_SASL_CYRUS
608static int smtp_auth_sasl(struct SmtpAccountData *adata, const char *mechlist)
609{
610 sasl_conn_t *saslconn = NULL;
611 sasl_interact_t *interaction = NULL;
612 const char *mech = NULL;
613 const char *data = NULL;
614 unsigned int len;
615 char *buf = NULL;
616 size_t bufsize = 0;
617 int rc, saslrc;
618
619 if (mutt_sasl_client_new(adata->conn, &saslconn) < 0)
620 return SMTP_AUTH_FAIL;
621
622 do
623 {
624 rc = sasl_client_start(saslconn, mechlist, &interaction, &data, &len, &mech);
625 if (rc == SASL_INTERACT)
626 mutt_sasl_interact(interaction);
627 } while (rc == SASL_INTERACT);
628
629 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
630 {
631 mutt_debug(LL_DEBUG2, "%s unavailable\n", NONULL(mech));
632 sasl_dispose(&saslconn);
633 return SMTP_AUTH_UNAVAIL;
634 }
635
636 if (!OptNoCurses)
637 {
638 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
639 mutt_message(_("Authenticating (%s)..."), mech);
640 }
641
642 bufsize = MAX((len * 2), 1024);
643 buf = mutt_mem_malloc(bufsize);
644
645 snprintf(buf, bufsize, "AUTH %s", mech);
646 if (len)
647 {
648 mutt_str_cat(buf, bufsize, " ");
649 if (sasl_encode64(data, len, buf + mutt_str_len(buf),
650 bufsize - mutt_str_len(buf), &len) != SASL_OK)
651 {
652 mutt_debug(LL_DEBUG1, "#1 error base64-encoding client response\n");
653 goto fail;
654 }
655 }
656 mutt_str_cat(buf, bufsize, "\r\n");
657
658 do
659 {
660 if (mutt_socket_send(adata->conn, buf) < 0)
661 goto fail;
662 rc = mutt_socket_readln_d(buf, bufsize, adata->conn, MUTT_SOCK_LOG_FULL);
663 if (rc < 0)
664 goto fail;
665 if (!valid_smtp_code(buf, rc, &rc))
666 goto fail;
667
668 if (rc != SMTP_READY)
669 break;
670
671 if (sasl_decode64(buf + 4, strlen(buf + 4), buf, bufsize - 1, &len) != SASL_OK)
672 {
673 mutt_debug(LL_DEBUG1, "error base64-decoding server response\n");
674 goto fail;
675 }
676
677 do
678 {
679 saslrc = sasl_client_step(saslconn, buf, len, &interaction, &data, &len);
680 if (saslrc == SASL_INTERACT)
681 mutt_sasl_interact(interaction);
682 } while (saslrc == SASL_INTERACT);
683
684 if (len)
685 {
686 if ((len * 2) > bufsize)
687 {
688 bufsize = len * 2;
689 mutt_mem_realloc(&buf, bufsize);
690 }
691 if (sasl_encode64(data, len, buf, bufsize, &len) != SASL_OK)
692 {
693 mutt_debug(LL_DEBUG1, "#2 error base64-encoding client response\n");
694 goto fail;
695 }
696 }
697 mutt_str_copy(buf + len, "\r\n", bufsize - len);
698 } while (rc == SMTP_READY && saslrc != SASL_FAIL);
699
700 if (smtp_success(rc))
701 {
702 mutt_sasl_setup_conn(adata->conn, saslconn);
703 FREE(&buf);
704 return SMTP_AUTH_SUCCESS;
705 }
706
707fail:
708 sasl_dispose(&saslconn);
709 FREE(&buf);
710 return SMTP_AUTH_FAIL;
711}
712#endif
713
721static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
722{
723 (void) method; // This is OAUTHBEARER
724 const char *authtype = xoauth2 ? "XOAUTH2" : "OAUTHBEARER";
725
726 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
727 mutt_message(_("Authenticating (%s)..."), authtype);
728
729 /* We get the access token from the smtp_oauth_refresh_command */
730 char *oauthbearer = mutt_account_getoauthbearer(&adata->conn->account, xoauth2);
731 if (!oauthbearer)
732 return SMTP_AUTH_FAIL;
733
734 size_t ilen = strlen(oauthbearer) + 30;
735 char *ibuf = mutt_mem_malloc(ilen);
736 snprintf(ibuf, ilen, "AUTH %s %s\r\n", authtype, oauthbearer);
737
738 int rc = mutt_socket_send(adata->conn, ibuf);
739 FREE(&oauthbearer);
740 FREE(&ibuf);
741
742 if (rc == -1)
743 return SMTP_AUTH_FAIL;
744 if (smtp_get_resp(adata) != 0)
745 return SMTP_AUTH_FAIL;
746
747 return SMTP_AUTH_SUCCESS;
748}
749
756static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
757{
758 return smtp_auth_oauth_xoauth2(adata, method, false);
759}
760
767static int smtp_auth_xoauth2(struct SmtpAccountData *adata, const char *method)
768{
769 return smtp_auth_oauth_xoauth2(adata, method, true);
770}
771
779static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
780{
781 (void) method; // This is PLAIN
782
783 char buf[1024] = { 0 };
784
785 /* Get username and password. Bail out of any can't be retrieved. */
786 if ((mutt_account_getuser(&adata->conn->account) < 0) ||
787 (mutt_account_getpass(&adata->conn->account) < 0))
788 {
789 goto error;
790 }
791
792 /* Build the initial client response. */
793 size_t len = mutt_sasl_plain_msg(buf, sizeof(buf), "AUTH PLAIN",
794 adata->conn->account.user,
795 adata->conn->account.user,
796 adata->conn->account.pass);
797
798 /* Terminate as per SMTP protocol. Bail out if there's no room left. */
799 if (snprintf(buf + len, sizeof(buf) - len, "\r\n") != 2)
800 {
801 goto error;
802 }
803
804 /* Send request, receive response (with a check for OK code). */
805 if ((mutt_socket_send(adata->conn, buf) < 0) || smtp_get_resp(adata))
806 {
807 goto error;
808 }
809
810 /* If we got here, auth was successful. */
811 return 0;
812
813error:
814 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
815 mutt_error(_("%s authentication failed"), "SASL");
816 return -1;
817}
818
826static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
827{
828 (void) method; // This is LOGIN
829
830 char b64[1024] = { 0 };
831 char buf[1026] = { 0 };
832
833 /* Get username and password. Bail out of any can't be retrieved. */
834 if ((mutt_account_getuser(&adata->conn->account) < 0) ||
835 (mutt_account_getpass(&adata->conn->account) < 0))
836 {
837 goto error;
838 }
839
840 /* Send the AUTH LOGIN request. */
841 if (mutt_socket_send(adata->conn, "AUTH LOGIN\r\n") < 0)
842 {
843 goto error;
844 }
845
846 /* Read the 334 VXNlcm5hbWU6 challenge ("Username:" base64-encoded) */
847 mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
848 if (!mutt_str_equal(buf, "334 VXNlcm5hbWU6"))
849 {
850 goto error;
851 }
852
853 /* Send the username */
854 size_t len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.user);
855 mutt_b64_encode(buf, len, b64, sizeof(b64));
856 snprintf(buf, sizeof(buf), "%s\r\n", b64);
857 if (mutt_socket_send(adata->conn, buf) < 0)
858 {
859 goto error;
860 }
861
862 /* Read the 334 UGFzc3dvcmQ6 challenge ("Password:" base64-encoded) */
863 mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
864 if (!mutt_str_equal(buf, "334 UGFzc3dvcmQ6"))
865 {
866 goto error;
867 }
868
869 /* Send the password */
870 len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.pass);
871 mutt_b64_encode(buf, len, b64, sizeof(b64));
872 snprintf(buf, sizeof(buf), "%s\r\n", b64);
873 if (mutt_socket_send(adata->conn, buf) < 0)
874 {
875 goto error;
876 }
877
878 /* Check the final response */
879 if (smtp_get_resp(adata) < 0)
880 {
881 goto error;
882 }
883
884 /* If we got here, auth was successful. */
885 return 0;
886
887error:
888 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
889 mutt_error(_("%s authentication failed"), "LOGIN");
890 return -1;
891}
892
896static const struct SmtpAuth SmtpAuthenticators[] = {
897 // clang-format off
898 { smtp_auth_oauth, "oauthbearer" },
899 { smtp_auth_xoauth2, "xoauth2" },
900 { smtp_auth_plain, "plain" },
901 { smtp_auth_login, "login" },
902#ifdef USE_SASL_CYRUS
903 { smtp_auth_sasl, NULL },
904#endif
905#ifdef USE_SASL_GNU
906 { smtp_auth_gsasl, NULL },
907#endif
908 // clang-format on
909};
910
919bool smtp_auth_is_valid(const char *authenticator)
920{
921 for (size_t i = 0; i < mutt_array_size(SmtpAuthenticators); i++)
922 {
923 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
924 if (auth->method && mutt_istr_equal(auth->method, authenticator))
925 return true;
926 }
927
928 return false;
929}
930
937static int smtp_authenticate(struct SmtpAccountData *adata)
938{
939 int r = SMTP_AUTH_UNAVAIL;
940
941 const struct Slist *c_smtp_authenticators = cs_subset_slist(adata->sub, "smtp_authenticators");
942 if (c_smtp_authenticators && (c_smtp_authenticators->count > 0))
943 {
944 mutt_debug(LL_DEBUG2, "Trying user-defined smtp_authenticators\n");
945
946 /* Try user-specified list of authentication methods */
947 struct ListNode *np = NULL;
948 STAILQ_FOREACH(np, &c_smtp_authenticators->head, entries)
949 {
950 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
951
952 for (size_t i = 0; i < mutt_array_size(SmtpAuthenticators); i++)
953 {
954 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
955 if (!auth->method || mutt_istr_equal(auth->method, np->data))
956 {
957 r = auth->authenticate(adata, np->data);
958 if (r == SMTP_AUTH_SUCCESS)
959 return r;
960 }
961 }
962 }
963 }
964 else
965 {
966 /* Fall back to default: any authenticator */
967#if defined(USE_SASL_CYRUS)
968 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_sasl, if using sasl.\n");
969 r = smtp_auth_sasl(adata, adata->auth_mechs);
970#elif defined(USE_SASL_GNU)
971 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_gsasl, if using gsasl.\n");
972 r = smtp_auth_gsasl(adata, adata->auth_mechs);
973#else
974 mutt_debug(LL_DEBUG2, "Falling back to using any authenticator available.\n");
975 /* Try all available authentication methods */
976 for (size_t i = 0; i < mutt_array_size(SmtpAuthenticators); i++)
977 {
978 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
979 mutt_debug(LL_DEBUG2, "Trying method %s\n", auth->method ? auth->method : "<variable>");
980 r = auth->authenticate(adata, auth->method);
981 if (r == SMTP_AUTH_SUCCESS)
982 return r;
983 }
984#endif
985 }
986
987 if (r != SMTP_AUTH_SUCCESS)
989
990 if (r == SMTP_AUTH_FAIL)
991 {
992 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
993 mutt_error(_("%s authentication failed"), "SASL");
994 }
995 else if (r == SMTP_AUTH_UNAVAIL)
996 {
997 mutt_error(_("No authenticators available"));
998 }
999
1000 return (r == SMTP_AUTH_SUCCESS) ? 0 : -1;
1001}
1002
1010static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
1011{
1012 int rc;
1013
1014 if (mutt_socket_open(adata->conn))
1015 return -1;
1016
1017 const bool force_auth = cs_subset_string(adata->sub, "smtp_user");
1018 esmtp |= force_auth;
1019
1020 /* get greeting string */
1021 rc = smtp_get_resp(adata);
1022 if (rc != 0)
1023 return rc;
1024
1025 rc = smtp_helo(adata, esmtp);
1026 if (rc != 0)
1027 return rc;
1028
1029#ifdef USE_SSL
1030 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
1031 const enum QuadOption c_ssl_starttls = cs_subset_quad(adata->sub, "ssl_starttls");
1032 enum QuadOption ans = MUTT_NO;
1033 if (adata->conn->ssf != 0)
1034 ans = MUTT_NO;
1035 else if (c_ssl_force_tls)
1036 ans = MUTT_YES;
1037 else if ((adata->capabilities & SMTP_CAP_STARTTLS) &&
1038 ((ans = query_quadoption(c_ssl_starttls, _("Secure connection with TLS?"))) == MUTT_ABORT))
1039 {
1040 return -1;
1041 }
1042
1043 if (ans == MUTT_YES)
1044 {
1045 if (mutt_socket_send(adata->conn, "STARTTLS\r\n") < 0)
1046 return SMTP_ERR_WRITE;
1047 rc = smtp_get_resp(adata);
1048 // Clear any data after the STARTTLS acknowledgement
1049 mutt_socket_empty(adata->conn);
1050 if (rc != 0)
1051 return rc;
1052
1053 if (mutt_ssl_starttls(adata->conn))
1054 {
1055 mutt_error(_("Could not negotiate TLS connection"));
1056 return -1;
1057 }
1058
1059 /* re-EHLO to get authentication mechanisms */
1060 rc = smtp_helo(adata, esmtp);
1061 if (rc != 0)
1062 return rc;
1063 }
1064#endif
1065
1066 if (force_auth || adata->conn->account.flags & MUTT_ACCT_USER)
1067 {
1068 if (!(adata->capabilities & SMTP_CAP_AUTH))
1069 {
1070 mutt_error(_("SMTP server does not support authentication"));
1071 return -1;
1072 }
1073
1074 return smtp_authenticate(adata);
1075 }
1076
1077 return 0;
1078}
1079
1092int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to,
1093 const struct AddressList *cc, const struct AddressList *bcc,
1094 const char *msgfile, bool eightbit, struct ConfigSubset *sub)
1095{
1096 struct SmtpAccountData adata = { 0 };
1097 struct ConnAccount cac = { { 0 } };
1098 const char *envfrom = NULL;
1099 char buf[1024] = { 0 };
1100 int rc = -1;
1101
1102 adata.sub = sub;
1103 adata.fqdn = mutt_fqdn(false, adata.sub);
1104 if (!adata.fqdn)
1105 adata.fqdn = NONULL(ShortHostname);
1106
1107 const struct Address *c_envelope_from_address = cs_subset_address(adata.sub, "envelope_from_address");
1108
1109 /* it might be better to synthesize an envelope from from user and host
1110 * but this condition is most likely arrived at accidentally */
1111 if (c_envelope_from_address)
1112 envfrom = c_envelope_from_address->mailbox;
1113 else if (from && !TAILQ_EMPTY(from))
1114 envfrom = TAILQ_FIRST(from)->mailbox;
1115 else
1116 {
1117 mutt_error(_("No from address given"));
1118 return -1;
1119 }
1120
1121 if (smtp_fill_account(&adata, &cac) < 0)
1122 return rc;
1123
1124 adata.conn = mutt_conn_find(&cac);
1125 if (!adata.conn)
1126 return -1;
1127
1128 const char *const c_dsn_return = cs_subset_string(adata.sub, "dsn_return");
1129
1130 do
1131 {
1132 /* send our greeting */
1133 rc = smtp_open(&adata, eightbit);
1134 if (rc != 0)
1135 break;
1136 FREE(&adata.auth_mechs);
1137
1138 /* send the sender's address */
1139 int len = snprintf(buf, sizeof(buf), "MAIL FROM:<%s>", envfrom);
1140 if (eightbit && (adata.capabilities & SMTP_CAP_EIGHTBITMIME))
1141 {
1142 mutt_strn_cat(buf, sizeof(buf), " BODY=8BITMIME", 15);
1143 len += 14;
1144 }
1145 if (c_dsn_return && (adata.capabilities & SMTP_CAP_DSN))
1146 len += snprintf(buf + len, sizeof(buf) - len, " RET=%s", c_dsn_return);
1147 if ((adata.capabilities & SMTP_CAP_SMTPUTF8) &&
1150 {
1151 snprintf(buf + len, sizeof(buf) - len, " SMTPUTF8");
1152 }
1153 mutt_strn_cat(buf, sizeof(buf), "\r\n", 3);
1154 if (mutt_socket_send(adata.conn, buf) == -1)
1155 {
1156 rc = SMTP_ERR_WRITE;
1157 break;
1158 }
1159 rc = smtp_get_resp(&adata);
1160 if (rc != 0)
1161 break;
1162
1163 /* send the recipient list */
1164 if ((rc = smtp_rcpt_to(&adata, to)) || (rc = smtp_rcpt_to(&adata, cc)) ||
1165 (rc = smtp_rcpt_to(&adata, bcc)))
1166 {
1167 break;
1168 }
1169
1170 /* send the message data */
1171 rc = smtp_data(&adata, msgfile);
1172 if (rc != 0)
1173 break;
1174
1175 mutt_socket_send(adata.conn, "QUIT\r\n");
1176
1177 rc = 0;
1178 } while (false);
1179
1180 mutt_socket_close(adata.conn);
1181 FREE(&adata.conn);
1182
1183 if (rc == SMTP_ERR_READ)
1184 mutt_error(_("SMTP session failed: read error"));
1185 else if (rc == SMTP_ERR_WRITE)
1186 mutt_error(_("SMTP session failed: write error"));
1187 else if (rc == SMTP_ERR_CODE)
1188 mutt_error(_("Invalid server response"));
1189
1190 return rc;
1191}
bool mutt_addrlist_uses_unicode(const struct AddressList *al)
Do any of a list of addresses use Unicode characters.
Definition: address.c:1497
bool mutt_addr_uses_unicode(const char *str)
Does this address use Unicode character.
Definition: address.c:1477
Email Address Handling.
const char * mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: atoi.c:179
size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen)
Convert raw bytes to null-terminated base64 string.
Definition: base64.c:88
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:365
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:409
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:248
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:85
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:268
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:49
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the config headers.
Connection Library.
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
Definition: connaccount.c:129
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:49
void mutt_account_unsetpass(struct ConnAccount *cac)
Unset ConnAccount's password.
Definition: connaccount.c:176
char * mutt_account_getoauthbearer(struct ConnAccount *cac, bool xoauth2)
Get an OAUTHBEARER/XOAUTH2 token.
Definition: connaccount.c:194
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
Structs that make up an email.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:151
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition: file.c:1585
char * ShortHostname
Short version of the hostname.
Definition: globals.c:39
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:81
int mutt_ssl_starttls(struct Connection *conn)
Negotiate TLS over an already opened connection.
Definition: gnutls.c:1143
#define mutt_error(...)
Definition: logging.h:87
#define mutt_message(...)
Definition: logging.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
const char * mutt_gsasl_get_mech(const char *requested_mech, const char *server_mechlist)
Pick a connection mechanism.
Definition: gsasl.c:162
int mutt_gsasl_client_new(struct Connection *conn, const char *mech, Gsasl_session **sctx)
Create a new GNU SASL client.
Definition: gsasl.c:197
void mutt_gsasl_client_finish(Gsasl_session **sctx)
Free a GNU SASL client.
Definition: gsasl.c:218
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:43
#define MAX(a, b)
Definition: memory.h:30
#define mutt_array_size(x)
Definition: memory.h:36
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:819
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:294
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:567
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:652
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:265
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
ConnAccount object used by POP and IMAP.
@ MUTT_ACCT_TYPE_SMTP
Smtp Account.
Definition: mutt_account.h:39
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:89
NeoMutt connections.
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
Progress bar.
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:51
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:86
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:73
struct Progress * progress_new(const char *msg, enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:118
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(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: question.c:386
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_EMPTY(head)
Definition: queue.h:721
int mutt_sasl_interact(sasl_interact_t *interaction)
Perform an SASL interaction with the user.
Definition: sasl.c:694
int mutt_sasl_client_new(struct Connection *conn, sasl_conn_t **saslconn)
Wrapper for sasl_client_new()
Definition: sasl.c:599
void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn)
Set up an SASL connection.
Definition: sasl.c:731
size_t mutt_sasl_plain_msg(char *buf, size_t buflen, const char *cmd, const char *authz, const char *user, const char *pass)
Construct a base64 encoded SASL PLAIN message.
Definition: sasl_plain.c:55
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:696
static int smtp_get_resp(struct SmtpAccountData *adata)
Read a command response from the SMTP server.
Definition: smtp.c:138
#define SMTPS_PORT
Definition: smtp.c:70
#define SMTP_CAP_NO_FLAGS
No flags are set.
Definition: smtp.c:81
#define SMTP_CAP_STARTTLS
Server supports STARTTLS command.
Definition: smtp.c:82
uint8_t SmtpCapFlags
SMTP server capabilities.
Definition: smtp.c:80
static int smtp_authenticate(struct SmtpAccountData *adata)
Authenticate to an SMTP server.
Definition: smtp.c:937
#define SMTP_ERR_READ
Definition: smtp.c:65
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition: smtp.c:919
static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
Authenticate an SMTP connection using OAUTHBEARER/XOAUTH2.
Definition: smtp.c:721
static const struct SmtpAuth SmtpAuthenticators[]
Accepted authentication methods.
Definition: smtp.c:896
#define SMTP_AUTH_UNAVAIL
Definition: smtp.c:73
static int smtp_helo(struct SmtpAccountData *adata, bool esmtp)
Say hello to an SMTP Server.
Definition: smtp.c:396
#define SMTP_ERR_CODE
Definition: smtp.c:67
#define SMTP_CAP_EIGHTBITMIME
Server supports 8-bit MIME content.
Definition: smtp.c:85
#define smtp_success(x)
Definition: smtp.c:61
#define SMTP_AUTH_FAIL
Definition: smtp.c:74
#define SMTP_CAP_AUTH
Server supports AUTH command.
Definition: smtp.c:83
static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
Send data to an SMTP server.
Definition: smtp.c:225
#define SMTP_ERR_WRITE
Definition: smtp.c:66
static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
Create ConnAccount object from SMTP Url.
Definition: smtp.c:342
#define SMTP_AUTH_SUCCESS
Definition: smtp.c:72
static const char * smtp_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
Definition: smtp.c:305
static int smtp_auth_xoauth2(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection using XOAUTH2.
Definition: smtp.c:767
#define SMTP_CAP_SMTPUTF8
Server accepts UTF-8 strings.
Definition: smtp.c:86
#define SMTP_CONTINUE
Definition: smtp.c:63
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:1092
#define SMTP_CAP_DSN
Server supports Delivery Status Notification.
Definition: smtp.c:84
static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text.
Definition: smtp.c:826
static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text.
Definition: smtp.c:779
static bool valid_smtp_code(char *buf, size_t buflen, int *n)
Is the is a valid SMTP return code?
Definition: smtp.c:127
static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection using OAUTHBEARER.
Definition: smtp.c:756
static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
Set the recipient to an Address.
Definition: smtp.c:188
static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
Open an SMTP Connection.
Definition: smtp.c:1010
#define SMTP_PORT
Definition: smtp.c:69
#define SMTP_READY
Definition: smtp.c:62
Send email to an SMTP server.
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:101
void mutt_socket_empty(struct Connection *conn)
Clear out any queued data.
Definition: socket.c:317
int mutt_socket_open(struct Connection *conn)
Simple wrapper.
Definition: socket.c:77
int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int dbg)
Read a line from a socket.
Definition: socket.c:250
#define MUTT_SOCK_LOG_FULL
Definition: socket.h:56
#define mutt_socket_readln(buf, buflen, conn)
Definition: socket.h:58
#define mutt_socket_send(conn, buf)
Definition: socket.h:59
#define mutt_socket_buffer_readln(buf, conn)
Definition: socket.h:63
#define mutt_socket_send_d(conn, buf, dbg)
Definition: socket.h:60
Key value store.
#define NONULL(x)
Definition: string2.h:37
An email address.
Definition: address.h:36
bool group
Group mailbox?
Definition: address.h:39
char * mailbox
Mailbox and host address.
Definition: address.h:38
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
A set of inherited config items.
Definition: subset.h:47
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)
Function to get some login credentials.
Definition: connaccount.h:68
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:70
unsigned short port
Port to connect to.
Definition: connaccount.h:58
unsigned int ssf
Security strength factor, in bits (see notes)
Definition: connection.h:51
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
String list.
Definition: slist.h:47
struct ListHead head
List containing values.
Definition: slist.h:48
size_t count
Number of values in list.
Definition: slist.h:49
Server connection data.
Definition: smtp.c:95
const char * fqdn
Fully-qualified domain name.
Definition: smtp.c:100
struct ConfigSubset * sub
Config scope.
Definition: smtp.c:99
struct Connection * conn
Server Connection.
Definition: smtp.c:98
const char * auth_mechs
Allowed authorisation mechanisms.
Definition: smtp.c:96
SmtpCapFlags capabilities
Server capabilities.
Definition: smtp.c:97
SMTP authentication multiplexor.
Definition: smtp.c:107
int(* authenticate)(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection.
Definition: smtp.c:114
const char * method
Name of authentication method supported, NULL means variable.
Definition: smtp.c:116
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:234
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
@ U_SMTPS
Url is smtps://.
Definition: url.h:44
@ U_SMTP
Url is smtp://.
Definition: url.h:43