NeoMutt  2025-12-11-911-gd8d604
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 "muttlib.h"
56#include "sendlib.h"
57#ifdef USE_SASL_GNU
58#include <gsasl.h>
59#endif
60#ifdef USE_SASL_CYRUS
61#include <sasl/sasl.h>
62#endif
63
65#define smtp_success(x) (((x) / 100) == 2)
66#define SMTP_READY 334
67#define SMTP_CONTINUE 354
68
69#define SMTP_ERR_READ -2
70#define SMTP_ERR_WRITE -3
71#define SMTP_ERR_CODE -4
72
73#define SMTP_PORT 25
74#define SMTPS_PORT 465
75
76#define SMTP_AUTH_SUCCESS 0
77#define SMTP_AUTH_UNAVAIL 1
78#define SMTP_AUTH_FAIL -1
79
84{
85 // clang-format off
88 SMTP_CAP_AUTH = 1U << 1,
89 SMTP_CAP_DSN = 1U << 2,
92 // clang-format on
93};
94typedef uint8_t SmtpCapFlags;
95
96#define SMTP_CAP_ALL ((1U << 5) - 1)
97
102{
103 const char *auth_mechs;
105 struct Connection *conn;
107 const char *fqdn;
108};
109
114{
123 int (*authenticate)(struct SmtpAccountData *adata, const char *method);
124
125 const char *method;
127};
128
135static bool valid_smtp_code(char *buf, int *n)
136{
137 return (mutt_str_atoi(buf, n) - buf) <= 3;
138}
139
146static int smtp_get_resp(struct SmtpAccountData *adata)
147{
148 int n;
149 char buf[1024] = { 0 };
150
151 do
152 {
153 n = mutt_socket_readln(buf, sizeof(buf), adata->conn);
154 if (n < 4)
155 {
156 /* read error, or no response code */
157 return SMTP_ERR_READ;
158 }
159 const char *s = buf + 4; /* Skip the response code and the space/dash */
160 size_t plen;
161
162 if (mutt_istr_startswith(s, "8BITMIME"))
163 {
165 }
166 else if ((plen = mutt_istr_startswith(s, "AUTH ")))
167 {
168 adata->capabilities |= SMTP_CAP_AUTH;
169 FREE(&adata->auth_mechs);
170 adata->auth_mechs = mutt_str_dup(s + plen);
171 }
172 else if (mutt_istr_startswith(s, "DSN"))
173 {
174 adata->capabilities |= SMTP_CAP_DSN;
175 }
176 else if (mutt_istr_startswith(s, "STARTTLS"))
177 {
179 }
180 else if (mutt_istr_startswith(s, "SMTPUTF8"))
181 {
183 }
184
185 if (!valid_smtp_code(buf, &n))
186 return SMTP_ERR_CODE;
187
188 } while (buf[3] == '-');
189
190 if (smtp_success(n) || (n == SMTP_CONTINUE))
191 return 0;
192
193 mutt_error(_("SMTP session failed: %s"), buf);
194 return -1;
195}
196
204static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
205{
206 if (!al)
207 return 0;
208
209 const char *const c_dsn_notify = cs_subset_string(adata->sub, "dsn_notify");
210
211 struct Address *a = NULL;
212 TAILQ_FOREACH(a, al, entries)
213 {
214 /* weed out group mailboxes, since those are for display only */
215 if (!a->mailbox || a->group)
216 {
217 continue;
218 }
219 char buf[1024] = { 0 };
220 if ((adata->capabilities & SMTP_CAP_DSN) && c_dsn_notify)
221 {
222 snprintf(buf, sizeof(buf), "RCPT TO:<%s> NOTIFY=%s\r\n",
223 buf_string(a->mailbox), c_dsn_notify);
224 }
225 else
226 {
227 snprintf(buf, sizeof(buf), "RCPT TO:<%s>\r\n", buf_string(a->mailbox));
228 }
229 if (mutt_socket_send(adata->conn, buf) == -1)
230 return SMTP_ERR_WRITE;
231 int rc = smtp_get_resp(adata);
232 if (rc != 0)
233 {
234 mutt_sleep(2);
235 mutt_error(_("SMTP session failed: cannot add recipient <%s>"),
236 buf_string(a->mailbox));
237 return rc;
238 }
239 }
240
241 return 0;
242}
243
251static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
252{
253 char buf[1024] = { 0 };
254 struct Progress *progress = NULL;
255 int rc = SMTP_ERR_WRITE;
256 int term = 0;
257 size_t buflen = 0;
258
259 FILE *fp = mutt_file_fopen(msgfile, "r");
260 if (!fp)
261 {
262 mutt_error(_("SMTP session failed: unable to open %s"), msgfile);
263 return -1;
264 }
265 const long size = mutt_file_get_size_fp(fp);
266 if (size == 0)
267 {
268 mutt_file_fclose(&fp);
269 return -1;
270 }
271 unlink(msgfile);
272 progress = progress_new(MUTT_PROGRESS_NET, size);
273 progress_set_message(progress, _("Sending message..."));
274
275 snprintf(buf, sizeof(buf), "DATA\r\n");
276 if (mutt_socket_send(adata->conn, buf) == -1)
277 {
278 mutt_file_fclose(&fp);
279 goto done;
280 }
281 rc = smtp_get_resp(adata);
282 if (rc != 0)
283 {
284 mutt_file_fclose(&fp);
285 goto done;
286 }
287
288 rc = SMTP_ERR_WRITE;
289 while (fgets(buf, sizeof(buf) - 1, fp))
290 {
291 buflen = mutt_str_len(buf);
292 term = buflen && buf[buflen - 1] == '\n';
293 if (term && ((buflen == 1) || (buf[buflen - 2] != '\r')))
294 snprintf(buf + buflen - 1, sizeof(buf) - buflen + 1, "\r\n");
295 if (buf[0] == '.')
296 {
297 if (mutt_socket_send_d(adata->conn, ".", MUTT_SOCK_LOG_FULL) == -1)
298 {
299 mutt_file_fclose(&fp);
300 goto done;
301 }
302 }
303 if (mutt_socket_send_d(adata->conn, buf, MUTT_SOCK_LOG_FULL) == -1)
304 {
305 mutt_file_fclose(&fp);
306 goto done;
307 }
308 progress_update(progress, MAX(0, ftell(fp)), -1);
309 }
310 if (!term && buflen &&
311 (mutt_socket_send_d(adata->conn, "\r\n", MUTT_SOCK_LOG_FULL) == -1))
312 {
313 mutt_file_fclose(&fp);
314 goto done;
315 }
316 mutt_file_fclose(&fp);
317
318 /* terminate the message body */
319 if (mutt_socket_send(adata->conn, ".\r\n") == -1)
320 goto done;
321
322 rc = smtp_get_resp(adata);
323
324done:
325 progress_free(&progress);
326 return rc;
327}
328
332static const char *smtp_get_field(enum ConnAccountField field, void *gf_data)
333{
334 struct SmtpAccountData *adata = gf_data;
335 if (!adata)
336 return NULL;
337
338 switch (field)
339 {
340 case MUTT_CA_LOGIN:
341 case MUTT_CA_USER:
342 {
343 const char *const c_smtp_user = cs_subset_string(adata->sub, "smtp_user");
344 return c_smtp_user;
345 }
346 case MUTT_CA_PASS:
347 {
348 const char *const c_smtp_pass = cs_subset_string(adata->sub, "smtp_pass");
349 return c_smtp_pass;
350 }
352 {
353 const char *const c_smtp_oauth_refresh_command = cs_subset_string(adata->sub, "smtp_oauth_refresh_command");
354 return c_smtp_oauth_refresh_command;
355 }
356 case MUTT_CA_HOST:
357 default:
358 return NULL;
359 }
360}
361
369static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
370{
371 cac->flags = 0;
372 cac->port = 0;
374 cac->service = "smtp";
376 cac->gf_data = adata;
377
378 const char *const c_smtp_url = cs_subset_string(adata->sub, "smtp_url");
379
380 struct Url *url = url_parse(c_smtp_url);
381 if (!url || ((url->scheme != U_SMTP) && (url->scheme != U_SMTPS)) ||
382 !url->host || (account_from_url(cac, url) < 0))
383 {
384 url_free(&url);
385 mutt_error(_("Invalid SMTP URL: %s"), c_smtp_url);
386 return -1;
387 }
388
389 if (url->scheme == U_SMTPS)
390 cac->flags |= MUTT_ACCT_SSL;
391
392 if (cac->port == 0)
393 {
394 if (cac->flags & MUTT_ACCT_SSL)
395 {
396 cac->port = SMTPS_PORT;
397 }
398 else
399 {
400 static unsigned short SmtpPort = 0;
401 if (SmtpPort == 0)
402 {
403 struct servent *service = getservbyname("smtp", "tcp");
404 if (service)
405 SmtpPort = ntohs(service->s_port);
406 else
407 SmtpPort = SMTP_PORT;
408 mutt_debug(LL_DEBUG3, "Using default SMTP port %d\n", SmtpPort);
409 }
410 cac->port = SmtpPort;
411 }
412 }
413
414 url_free(&url);
415 return 0;
416}
417
425static int smtp_helo(struct SmtpAccountData *adata, bool esmtp)
426{
428
429 if (!esmtp)
430 {
431 /* if TLS or AUTH are requested, use EHLO */
432 if (adata->conn->account.flags & MUTT_ACCT_USER)
433 esmtp = true;
434#ifdef USE_SSL
435 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
436 const enum QuadOption c_ssl_starttls = cs_subset_quad(adata->sub, "ssl_starttls");
437
438 if (c_ssl_force_tls || (c_ssl_starttls != MUTT_NO))
439 esmtp = true;
440#endif
441 }
442
443 char buf[1024] = { 0 };
444 snprintf(buf, sizeof(buf), "%s %s\r\n", esmtp ? "EHLO" : "HELO", adata->fqdn);
445 /* XXX there should probably be a wrapper in mutt_socket.c that
446 * repeatedly calls adata->conn->write until all data is sent. This
447 * currently doesn't check for a short write. */
448 if (mutt_socket_send(adata->conn, buf) == -1)
449 return SMTP_ERR_WRITE;
450 return smtp_get_resp(adata);
451}
452
453#if defined(USE_SASL_CYRUS) || defined(USE_SASL_GNU)
460static int smtp_code(const struct Buffer *buf, int *n)
461{
462 if (buf_len(buf) < 3)
463 return false;
464
465 char code[4] = { 0 };
466 const char *str = buf_string(buf);
467
468 code[0] = str[0];
469 code[1] = str[1];
470 code[2] = str[2];
471 code[3] = 0;
472
473 const char *end = mutt_str_atoi(code, n);
474 if (!end || (*end != '\0'))
475 return false;
476 return true;
477}
478
490static int smtp_get_auth_response(struct Connection *conn, struct Buffer *input_buf,
491 int *smtp_rc, struct Buffer *response_buf)
492{
493 buf_reset(response_buf);
494 do
495 {
496 if (mutt_socket_buffer_readln(input_buf, conn) < 0)
497 return -1;
498 if (!smtp_code(input_buf, smtp_rc))
499 {
500 return -1;
501 }
502
503 if (*smtp_rc != SMTP_READY)
504 break;
505
506 const char *smtp_response = input_buf->data + 3;
507 if (*smtp_response)
508 {
509 smtp_response++;
510 buf_addstr(response_buf, smtp_response);
511 }
512 } while (buf_at(input_buf, 3) == '-');
513
514 return 0;
515}
516#endif
517
518#ifdef USE_SASL_GNU
526static int smtp_auth_gsasl(struct SmtpAccountData *adata, const char *mechlist)
527{
528 Gsasl_session *gsasl_session = NULL;
529 struct Buffer *input_buf = NULL, *output_buf = NULL, *smtp_response_buf = NULL;
530 int rc = SMTP_AUTH_FAIL, gsasl_rc = GSASL_OK, smtp_rc;
531 bool first_response = true;
532
533 const char *chosen_mech = mutt_gsasl_get_mech(mechlist, adata->auth_mechs);
534 if (!chosen_mech)
535 {
536 mutt_debug(LL_DEBUG2, "returned no usable mech\n");
537 return SMTP_AUTH_UNAVAIL;
538 }
539
540 mutt_debug(LL_DEBUG2, "using mech %s\n", chosen_mech);
541
542 if (mutt_gsasl_client_new(adata->conn, chosen_mech, &gsasl_session) < 0)
543 {
544 mutt_debug(LL_DEBUG1, "Error allocating GSASL connection\n");
545 return SMTP_AUTH_UNAVAIL;
546 }
547
548 if (OptGui)
549 mutt_message(_("Authenticating (%s)..."), chosen_mech);
550
551 input_buf = buf_pool_get();
552 output_buf = buf_pool_get();
553 smtp_response_buf = buf_pool_get();
554
555 buf_printf(output_buf, "AUTH %s", chosen_mech);
556
557 /* Work around broken SMTP servers. See Debian #1010658.
558 * The msmtp source also forces IR for PLAIN because the author
559 * encountered difficulties with a server requiring it. */
560 if (mutt_str_equal(chosen_mech, "PLAIN"))
561 {
562 first_response = false;
563 char *gsasl_step_output = NULL;
564 gsasl_rc = gsasl_step64(gsasl_session, "", &gsasl_step_output);
565 if (gsasl_rc != GSASL_NEEDS_MORE && gsasl_rc != GSASL_OK)
566 {
567 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
568 gsasl_strerror(gsasl_rc));
569 goto fail;
570 }
571
572 buf_addch(output_buf, ' ');
573 buf_addstr(output_buf, gsasl_step_output);
574 gsasl_free(gsasl_step_output);
575 }
576
577 buf_addstr(output_buf, "\r\n");
578
579 do
580 {
581 if (mutt_socket_send(adata->conn, buf_string(output_buf)) < 0)
582 goto fail;
583
584 if (smtp_get_auth_response(adata->conn, input_buf, &smtp_rc, smtp_response_buf) < 0)
585 goto fail;
586
587 if (smtp_rc != SMTP_READY)
588 break;
589
590 /* Another workaround for broken SMTP servers. Instead of an
591 * empty challenge, some MS servers return a meaningless
592 * non-BASE64 encoded response in the initial reply, e.g. "334
593 * GSSAPI supported".
594 */
595 if (first_response)
596 {
597 first_response = false;
598 /* Use input_buf as a temp buffer. We've already processed the input */
599 if (mutt_b64_buffer_decode(input_buf, buf_string(smtp_response_buf)) < 0)
600 buf_reset(smtp_response_buf);
601 }
602
603 char *gsasl_step_output = NULL;
604 gsasl_rc = gsasl_step64(gsasl_session, buf_string(smtp_response_buf), &gsasl_step_output);
605 if ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK))
606 {
607 buf_strcpy(output_buf, gsasl_step_output);
608 buf_addstr(output_buf, "\r\n");
609 gsasl_free(gsasl_step_output);
610 }
611 else
612 {
613 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
614 gsasl_strerror(gsasl_rc));
615 }
616 } while ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK));
617
618 if (smtp_rc == SMTP_READY)
619 {
620 mutt_socket_send(adata->conn, "*\r\n");
621 goto fail;
622 }
623
624 if (smtp_success(smtp_rc) && (gsasl_rc == GSASL_OK))
626
627fail:
628 buf_pool_release(&input_buf);
629 buf_pool_release(&output_buf);
630 buf_pool_release(&smtp_response_buf);
631 mutt_gsasl_client_finish(&gsasl_session);
632
633 if (rc == SMTP_AUTH_FAIL)
634 mutt_debug(LL_DEBUG2, "%s failed\n", chosen_mech);
635
636 return rc;
637}
638#endif
639
640#ifdef USE_SASL_CYRUS
648static int smtp_auth_sasl(struct SmtpAccountData *adata, const char *mechlist)
649{
650 sasl_conn_t *saslconn = NULL;
651 sasl_interact_t *interaction = NULL;
652 const char *mech = NULL;
653 const char *data = NULL;
654 unsigned int data_len = 0;
655 struct Buffer *temp_buf = NULL;
656 struct Buffer *output_buf = NULL;
657 struct Buffer *smtp_response_buf = NULL;
658 int rc = SMTP_AUTH_FAIL;
659 int rc_sasl;
660 int rc_smtp;
661
662 if (mutt_sasl_client_new(adata->conn, &saslconn) < 0)
663 return SMTP_AUTH_FAIL;
664
665 /* Perform SASL client handshake: start negotiation with the server,
666 * handling any interactive prompts from the SASL library */
667 do
668 {
669 rc_sasl = sasl_client_start(saslconn, mechlist, &interaction, &data, &data_len, &mech);
670 if (rc_sasl == SASL_INTERACT)
671 mutt_sasl_interact(interaction);
672 } while (rc_sasl == SASL_INTERACT);
673
674 if ((rc_sasl != SASL_OK) && (rc_sasl != SASL_CONTINUE))
675 {
676 mutt_debug(LL_DEBUG2, "%s unavailable\n", NONULL(mech));
677 sasl_dispose(&saslconn);
678 return SMTP_AUTH_UNAVAIL;
679 }
680
681 if (OptGui)
682 {
683 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
684 mutt_message(_("Authenticating (%s)..."), mech);
685 }
686
687 /* Build the initial AUTH command, optionally including the first
688 * base64-encoded SASL response as part of the AUTH line */
689 temp_buf = buf_pool_get();
690 output_buf = buf_pool_get();
691 smtp_response_buf = buf_pool_get();
692
693 buf_printf(output_buf, "AUTH %s", mech);
694 if (data_len > 0)
695 {
696 buf_addch(output_buf, ' ');
697 mutt_b64_buffer_encode(temp_buf, data, data_len);
698 buf_addstr(output_buf, buf_string(temp_buf));
699 }
700 buf_addstr(output_buf, "\r\n");
701
702 /* Main SASL challenge/response loop: send base64-encoded data to the
703 * server, decode its response, and pass it to sasl_client_step() */
704 do
705 {
706 if (mutt_socket_send(adata->conn, buf_string(output_buf)) < 0)
707 goto fail;
708
709 if (smtp_get_auth_response(adata->conn, temp_buf, &rc_smtp, smtp_response_buf) < 0)
710 goto fail;
711
712 if (rc_smtp != SMTP_READY)
713 break;
714
715 if (mutt_b64_buffer_decode(temp_buf, buf_string(smtp_response_buf)) < 0)
716 {
717 mutt_debug(LL_DEBUG1, "error base64-decoding server response\n");
718 goto fail;
719 }
720
721 do
722 {
723 rc_sasl = sasl_client_step(saslconn, buf_string(temp_buf), buf_len(temp_buf),
724 &interaction, &data, &data_len);
725 if (rc_sasl == SASL_INTERACT)
726 mutt_sasl_interact(interaction);
727 } while (rc_sasl == SASL_INTERACT);
728
729 if (data_len > 0)
730 mutt_b64_buffer_encode(output_buf, data, data_len);
731 else
732 buf_reset(output_buf);
733
734 buf_addstr(output_buf, "\r\n");
735 } while (rc_sasl != SASL_FAIL);
736
737 /* Check final SMTP result and set up SASL security layer on success */
738 if (smtp_success(rc_smtp))
739 {
740 mutt_sasl_setup_conn(adata->conn, saslconn);
742 }
743 else
744 {
745 if (rc_smtp == SMTP_READY)
746 mutt_socket_send(adata->conn, "*\r\n");
747 sasl_dispose(&saslconn);
748 }
749
750fail:
751 buf_pool_release(&temp_buf);
752 buf_pool_release(&output_buf);
753 buf_pool_release(&smtp_response_buf);
754 return rc;
755}
756#endif
757
765static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
766{
767 /* If they did not explicitly request or configure oauth then fail quietly */
768 const char *const c_smtp_oauth_refresh_command = cs_subset_string(NeoMutt->sub, "smtp_oauth_refresh_command");
769 if (!method && !c_smtp_oauth_refresh_command)
770 return SMTP_AUTH_UNAVAIL;
771
772 const char *authtype = xoauth2 ? "XOAUTH2" : "OAUTHBEARER";
773
774 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
775 mutt_message(_("Authenticating (%s)..."), authtype);
776
777 /* We get the access token from the smtp_oauth_refresh_command */
778 char *oauthbearer = mutt_account_getoauthbearer(&adata->conn->account, xoauth2);
779 if (!oauthbearer)
780 return SMTP_AUTH_FAIL;
781
782 char *ibuf = NULL;
783 mutt_str_asprintf(&ibuf, "AUTH %s %s\r\n", authtype, oauthbearer);
784
785 int rc = mutt_socket_send(adata->conn, ibuf);
786 FREE(&oauthbearer);
787 FREE(&ibuf);
788
789 if (rc == -1)
790 return SMTP_AUTH_FAIL;
791 if (smtp_get_resp(adata) != 0)
792 return SMTP_AUTH_FAIL;
793
794 return SMTP_AUTH_SUCCESS;
795}
796
803static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
804{
805 return smtp_auth_oauth_xoauth2(adata, method, false);
806}
807
814static int smtp_auth_xoauth2(struct SmtpAccountData *adata, const char *method)
815{
816 return smtp_auth_oauth_xoauth2(adata, method, true);
817}
818
828static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
829{
830 struct Buffer *buf = NULL;
831 struct ConnAccount *cac = &adata->conn->account;
832 int rc = -1;
833
834 /* Get username and password. Bail out of any can't be retrieved. */
835 if ((mutt_account_getuser(cac) < 0) || (mutt_account_getpass(cac) < 0))
836 goto error;
837
838 /* Build the initial client response. */
839 buf = buf_pool_get();
840 mutt_sasl_plain_msg(buf, "AUTH PLAIN", cac->user, cac->user, cac->pass);
841 buf_add_printf(buf, "\r\n");
842
843 /* Send request, receive response (with a check for OK code). */
844 if ((mutt_socket_send(adata->conn, buf_string(buf)) < 0) || smtp_get_resp(adata))
845 goto error;
846
847 rc = 0; // Auth was successful
848
849error:
850 if (rc != 0)
851 {
852 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
853 mutt_error(_("%s authentication failed"), "SASL");
854 }
855 buf_pool_release(&buf);
856 return rc;
857}
858
868static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
869{
870 char b64[1024] = { 0 };
871 char buf[1026] = { 0 };
872
873 /* Get username and password. Bail out of any can't be retrieved. */
874 if ((mutt_account_getuser(&adata->conn->account) < 0) ||
875 (mutt_account_getpass(&adata->conn->account) < 0))
876 {
877 goto error;
878 }
879
880 /* Send the AUTH LOGIN request. */
881 if (mutt_socket_send(adata->conn, "AUTH LOGIN\r\n") < 0)
882 {
883 goto error;
884 }
885
886 /* Read the 334 VXNlcm5hbWU6 challenge ("Username:" base64-encoded) */
887 int rc = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
888 if ((rc < 0) || !mutt_str_equal(buf, "334 VXNlcm5hbWU6"))
889 {
890 goto error;
891 }
892
893 /* Send the username */
894 size_t len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.user);
895 mutt_b64_encode(buf, len, b64, sizeof(b64));
896 snprintf(buf, sizeof(buf), "%s\r\n", b64);
897 if (mutt_socket_send(adata->conn, buf) < 0)
898 {
899 goto error;
900 }
901
902 /* Read the 334 UGFzc3dvcmQ6 challenge ("Password:" base64-encoded) */
903 rc = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
904 if ((rc < 0) || !mutt_str_equal(buf, "334 UGFzc3dvcmQ6"))
905 {
906 goto error;
907 }
908
909 /* Send the password */
910 len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.pass);
911 mutt_b64_encode(buf, len, b64, sizeof(b64));
912 snprintf(buf, sizeof(buf), "%s\r\n", b64);
913 if (mutt_socket_send(adata->conn, buf) < 0)
914 {
915 goto error;
916 }
917
918 /* Check the final response */
919 if (smtp_get_resp(adata) < 0)
920 {
921 goto error;
922 }
923
924 /* If we got here, auth was successful. */
925 return 0;
926
927error:
928 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
929 mutt_error(_("%s authentication failed"), "LOGIN");
930 return -1;
931}
932
936static const struct SmtpAuth SmtpAuthenticators[] = {
937 // clang-format off
938 { smtp_auth_oauth, "oauthbearer" },
939 { smtp_auth_xoauth2, "xoauth2" },
940 { smtp_auth_plain, "plain" },
941 { smtp_auth_login, "login" },
942#ifdef USE_SASL_CYRUS
943 { smtp_auth_sasl, NULL },
944#endif
945#ifdef USE_SASL_GNU
946 { smtp_auth_gsasl, NULL },
947#endif
948 // clang-format on
949};
950
959bool smtp_auth_is_valid(const char *authenticator)
960{
961 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
962 {
963 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
964 if (auth->method && mutt_istr_equal(auth->method, authenticator))
965 return true;
966 }
967
968 return false;
969}
970
977static int smtp_authenticate(struct SmtpAccountData *adata)
978{
979 int r = SMTP_AUTH_UNAVAIL;
980
981 const struct Slist *c_smtp_authenticators = cs_subset_slist(adata->sub, "smtp_authenticators");
982 if (c_smtp_authenticators && (c_smtp_authenticators->count > 0))
983 {
984 mutt_debug(LL_DEBUG2, "Trying user-defined smtp_authenticators\n");
985
986 /* Try user-specified list of authentication methods */
987 struct ListNode *np = NULL;
988 STAILQ_FOREACH(np, &c_smtp_authenticators->head, entries)
989 {
990 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
991
992 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
993 {
994 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
995 if (!auth->method || mutt_istr_equal(auth->method, np->data))
996 {
997 r = auth->authenticate(adata, np->data);
998 if (r == SMTP_AUTH_SUCCESS)
999 return r;
1000 }
1001 }
1002 }
1003 }
1004 else
1005 {
1006 /* Fall back to default: any authenticator */
1007#if defined(USE_SASL_CYRUS)
1008 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_sasl, if using sasl\n");
1009 r = smtp_auth_sasl(adata, adata->auth_mechs);
1010#elif defined(USE_SASL_GNU)
1011 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_gsasl, if using gsasl\n");
1012 r = smtp_auth_gsasl(adata, adata->auth_mechs);
1013#else
1014 mutt_debug(LL_DEBUG2, "Falling back to using any authenticator available\n");
1015 /* Try all available authentication methods */
1016 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
1017 {
1018 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
1019 mutt_debug(LL_DEBUG2, "Trying method %s\n", auth->method ? auth->method : "<variable>");
1020 r = auth->authenticate(adata, auth->method);
1021 if (r == SMTP_AUTH_SUCCESS)
1022 return r;
1023 }
1024#endif
1025 }
1026
1027 if (r != SMTP_AUTH_SUCCESS)
1029
1030 if (r == SMTP_AUTH_FAIL)
1031 {
1032 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
1033 mutt_error(_("%s authentication failed"), "SASL");
1034 }
1035 else if (r == SMTP_AUTH_UNAVAIL)
1036 {
1037 mutt_error(_("No authenticators available"));
1038 }
1039
1040 return (r == SMTP_AUTH_SUCCESS) ? 0 : -1;
1041}
1042
1050static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
1051{
1052 int rc;
1053
1054 if (mutt_socket_open(adata->conn))
1055 return -1;
1056
1057 const bool force_auth = cs_subset_string(adata->sub, "smtp_user");
1058 esmtp |= force_auth;
1059
1060 /* get greeting string */
1061 rc = smtp_get_resp(adata);
1062 if (rc != 0)
1063 return rc;
1064
1065 rc = smtp_helo(adata, esmtp);
1066 if (rc != 0)
1067 return rc;
1068
1069#ifdef USE_SSL
1070 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
1071 enum QuadOption ans = MUTT_NO;
1072 if (adata->conn->ssf != 0)
1073 ans = MUTT_NO;
1074 else if (c_ssl_force_tls)
1075 ans = MUTT_YES;
1076 else if ((adata->capabilities & SMTP_CAP_STARTTLS) &&
1077 ((ans = query_quadoption(_("Secure connection with TLS?"),
1078 adata->sub, "ssl_starttls")) == MUTT_ABORT))
1079 {
1080 return -1;
1081 }
1082
1083 if (ans == MUTT_YES)
1084 {
1085 if (mutt_socket_send(adata->conn, "STARTTLS\r\n") < 0)
1086 return SMTP_ERR_WRITE;
1087 rc = smtp_get_resp(adata);
1088 // Clear any data after the STARTTLS acknowledgement
1089 mutt_socket_empty(adata->conn);
1090 if (rc != 0)
1091 return rc;
1092
1093 if (mutt_ssl_starttls(adata->conn) != 0)
1094 {
1095 mutt_error(_("Could not negotiate TLS connection"));
1096 return -1;
1097 }
1098
1099 /* re-EHLO to get authentication mechanisms */
1100 rc = smtp_helo(adata, esmtp);
1101 if (rc != 0)
1102 return rc;
1103 }
1104#endif
1105
1106 if (force_auth || adata->conn->account.flags & MUTT_ACCT_USER)
1107 {
1108 if (!(adata->capabilities & SMTP_CAP_AUTH))
1109 {
1110 mutt_error(_("SMTP server does not support authentication"));
1111 return -1;
1112 }
1113
1114 return smtp_authenticate(adata);
1115 }
1116
1117 return 0;
1118}
1119
1132int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to,
1133 const struct AddressList *cc, const struct AddressList *bcc,
1134 const char *msgfile, bool eightbit, struct ConfigSubset *sub)
1135{
1136 struct SmtpAccountData adata = { 0 };
1137 struct ConnAccount cac = { { 0 } };
1138 const char *envfrom = NULL;
1139 int rc = -1;
1140
1141 adata.sub = sub;
1142 adata.fqdn = mutt_fqdn(false, adata.sub);
1143 if (!adata.fqdn)
1144 adata.fqdn = NONULL(ShortHostname);
1145
1146 const struct Address *c_envelope_from_address = cs_subset_address(adata.sub, "envelope_from_address");
1147
1148 if (smtp_fill_account(&adata, &cac) < 0)
1149 return rc;
1150
1151 adata.conn = mutt_conn_find(&cac);
1152 if (!adata.conn)
1153 return -1;
1154
1155 /* it might be better to synthesize an envelope from from user and host
1156 * but this condition is most likely arrived at accidentally */
1157 if (c_envelope_from_address)
1158 {
1159 envfrom = buf_string(c_envelope_from_address->mailbox);
1160 }
1161 else if (from && !TAILQ_EMPTY(from))
1162 {
1163 envfrom = buf_string(TAILQ_FIRST(from)->mailbox);
1164 }
1165 else
1166 {
1167 mutt_error(_("No from address given"));
1168 mutt_socket_close(adata.conn);
1169 return -1;
1170 }
1171
1172 const char *const c_dsn_return = cs_subset_string(adata.sub, "dsn_return");
1173
1174 struct Buffer *buf = buf_pool_get();
1175 do
1176 {
1177 /* send our greeting */
1178 rc = smtp_open(&adata, eightbit);
1179 if (rc != 0)
1180 break;
1181 FREE(&adata.auth_mechs);
1182
1183 /* send the sender's address */
1184 buf_printf(buf, "MAIL FROM:<%s>", envfrom);
1185 if (eightbit && (adata.capabilities & SMTP_CAP_EIGHTBITMIME))
1186 buf_addstr(buf, " BODY=8BITMIME");
1187
1188 if (c_dsn_return && (adata.capabilities & SMTP_CAP_DSN))
1189 buf_add_printf(buf, " RET=%s", c_dsn_return);
1190
1191 if ((adata.capabilities & SMTP_CAP_SMTPUTF8) &&
1194 {
1195 buf_addstr(buf, " SMTPUTF8");
1196 }
1197 buf_addstr(buf, "\r\n");
1198 if (mutt_socket_send(adata.conn, buf_string(buf)) == -1)
1199 {
1200 rc = SMTP_ERR_WRITE;
1201 break;
1202 }
1203 rc = smtp_get_resp(&adata);
1204 if (rc != 0)
1205 break;
1206
1207 /* send the recipient list */
1208 if ((rc = smtp_rcpt_to(&adata, to)) || (rc = smtp_rcpt_to(&adata, cc)) ||
1209 (rc = smtp_rcpt_to(&adata, bcc)))
1210 {
1211 break;
1212 }
1213
1214 /* send the message data */
1215 rc = smtp_data(&adata, msgfile);
1216 if (rc != 0)
1217 break;
1218
1219 mutt_socket_send(adata.conn, "QUIT\r\n");
1220
1221 rc = 0;
1222 } while (false);
1223
1224 mutt_socket_close(adata.conn);
1225 FREE(&adata.conn);
1226 FREE(&adata.auth_mechs);
1227
1228 if (rc == SMTP_ERR_READ)
1229 mutt_error(_("SMTP session failed: read error"));
1230 else if (rc == SMTP_ERR_WRITE)
1231 mutt_error(_("SMTP session failed: write error"));
1232 else if (rc == SMTP_ERR_CODE)
1233 mutt_error(_("Invalid server response"));
1234
1235 buf_pool_release(&buf);
1236 return rc;
1237}
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
@ MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition connaccount.h:51
@ MUTT_ACCT_USER
User field has been set.
Definition connaccount.h:48
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:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
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:332
#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:814
static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text - Implements SmtpAuth::authenticate() -.
Definition smtp.c:868
static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text - Implements SmtpAuth::authenticate() -.
Definition smtp.c:828
static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection using OAUTHBEARER - Implements SmtpAuth::authenticate() -.
Definition smtp.c:803
const char * mutt_gsasl_get_mech(const char *requested_mech, const char *server_mechlist)
Pick a connection mechanism.
Definition gsasl.c:166
int mutt_gsasl_client_new(struct Connection *conn, const char *mech, Gsasl_session **sctx)
Create a new GNU SASL client.
Definition gsasl.c:203
void mutt_gsasl_client_finish(Gsasl_session **sctx)
Free a GNU SASL client.
Definition gsasl.c:225
@ 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.
void mutt_sleep(short s)
Sleep for a while.
Definition muttlib.c:787
Some miscellaneous functions.
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:708
int mutt_sasl_client_new(struct Connection *conn, sasl_conn_t **saslconn)
Wrapper for sasl_client_new()
Definition sasl.c:610
void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn)
Set up an SASL connection.
Definition sasl.c:744
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:146
#define SMTPS_PORT
Default SMTPS (SMTP over SSL) port.
Definition smtp.c:74
uint8_t SmtpCapFlags
Definition smtp.c:94
static int smtp_authenticate(struct SmtpAccountData *adata)
Authenticate to an SMTP server.
Definition smtp.c:977
#define SMTP_ERR_READ
Error reading from server.
Definition smtp.c:69
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition smtp.c:959
static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
Authenticate an SMTP connection using OAUTHBEARER/XOAUTH2.
Definition smtp.c:765
static const struct SmtpAuth SmtpAuthenticators[]
Accepted authentication methods.
Definition smtp.c:936
static bool valid_smtp_code(char *buf, int *n)
Is the is a valid SMTP return code?
Definition smtp.c:135
#define SMTP_AUTH_UNAVAIL
Authentication method unavailable.
Definition smtp.c:77
static int smtp_helo(struct SmtpAccountData *adata, bool esmtp)
Say hello to an SMTP Server.
Definition smtp.c:425
#define SMTP_ERR_CODE
Invalid server response code.
Definition smtp.c:71
#define smtp_success(x)
Check if SMTP response code indicates success (2xx codes)
Definition smtp.c:65
#define SMTP_AUTH_FAIL
Authentication failed.
Definition smtp.c:78
static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
Send data to an SMTP server.
Definition smtp.c:251
#define SMTP_ERR_WRITE
Error writing to server.
Definition smtp.c:70
static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
Create ConnAccount object from SMTP Url.
Definition smtp.c:369
#define SMTP_AUTH_SUCCESS
Authentication completed successfully.
Definition smtp.c:76
SmtpCapFlag
SMTP server capabilities.
Definition smtp.c:84
@ SMTP_CAP_SMTPUTF8
Server accepts UTF-8 strings.
Definition smtp.c:91
@ SMTP_CAP_EIGHTBITMIME
Server supports 8-bit MIME content.
Definition smtp.c:90
@ SMTP_CAP_DSN
Server supports Delivery Status Notification.
Definition smtp.c:89
@ SMTP_CAP_NONE
No flags are set.
Definition smtp.c:86
@ SMTP_CAP_AUTH
Server supports AUTH command.
Definition smtp.c:88
@ SMTP_CAP_STARTTLS
Server supports STARTTLS command.
Definition smtp.c:87
#define SMTP_CONTINUE
SMTP server ready to accept message data.
Definition smtp.c:67
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:1132
static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
Set the recipient to an Address.
Definition smtp.c:204
static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
Open an SMTP Connection.
Definition smtp.c:1050
#define SMTP_PORT
Default SMTP port.
Definition smtp.c:73
#define SMTP_READY
SMTP server ready for authentication data.
Definition smtp.c:66
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:59
char user[128]
Username.
Definition connaccount.h:62
char pass[256]
Password.
Definition connaccount.h:63
const char * service
Name of the service, e.g. "imap".
Definition connaccount.h:67
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition connaccount.h:76
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition connaccount.h:65
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition connaccount.h:66
void * gf_data
Private data to pass to get_field()
Definition connaccount.h:78
unsigned short port
Port to connect to.
Definition connaccount.h:64
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:102
const char * fqdn
Fully-qualified domain name.
Definition smtp.c:107
struct ConfigSubset * sub
Config scope.
Definition smtp.c:106
struct Connection * conn
Server Connection.
Definition smtp.c:105
const char * auth_mechs
Allowed authorisation mechanisms.
Definition smtp.c:103
SmtpCapFlags capabilities
Server capabilities.
Definition smtp.c:104
SMTP authentication multiplexor.
Definition smtp.c:114
int(* authenticate)(struct SmtpAccountData *adata, const char *method)
Definition smtp.c:123
const char * method
Name of authentication method supported, NULL means variable.
Definition smtp.c:125
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:242
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