NeoMutt  2025-12-11-1061-g88ae84
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 = 0;
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
459static int smtp_code(const struct Buffer *buf, int *n)
460{
461 if (buf_len(buf) < 3)
462 return false;
463
464 char code[4] = { 0 };
465 const char *str = buf_string(buf);
466
467 code[0] = str[0];
468 code[1] = str[1];
469 code[2] = str[2];
470 code[3] = 0;
471
472 const char *end = mutt_str_atoi(code, n);
473 if (!end || (*end != '\0'))
474 return false;
475 return true;
476}
477
489static int smtp_get_auth_response(struct Connection *conn, struct Buffer *input_buf,
490 int *smtp_rc, struct Buffer *response_buf)
491{
492 buf_reset(response_buf);
493 do
494 {
495 if (mutt_socket_buffer_readln(input_buf, conn) < 0)
496 return -1;
497 if (!smtp_code(input_buf, smtp_rc))
498 {
499 return -1;
500 }
501
502 if (*smtp_rc != SMTP_READY)
503 break;
504
505 const char *smtp_response = input_buf->data + 3;
506 if (*smtp_response)
507 {
508 smtp_response++;
509 buf_addstr(response_buf, smtp_response);
510 }
511 } while (buf_at(input_buf, 3) == '-');
512
513 return 0;
514}
515
516#ifdef USE_SASL_GNU
524static int smtp_auth_gsasl(struct SmtpAccountData *adata, const char *mechlist)
525{
526 Gsasl_session *gsasl_session = NULL;
527 struct Buffer *input_buf = NULL;
528 struct Buffer *output_buf = NULL;
529 struct Buffer *smtp_response_buf = NULL;
530 int rc = SMTP_AUTH_FAIL;
531 int gsasl_rc = GSASL_OK;
532 int smtp_rc = 0;
533 bool first_response = true;
534
535 const char *chosen_mech = mutt_gsasl_get_mech(mechlist, adata->auth_mechs);
536 if (!chosen_mech)
537 {
538 mutt_debug(LL_DEBUG2, "returned no usable mech\n");
539 return SMTP_AUTH_UNAVAIL;
540 }
541
542 mutt_debug(LL_DEBUG2, "using mech %s\n", chosen_mech);
543
544 if (mutt_gsasl_client_new(adata->conn, chosen_mech, &gsasl_session) < 0)
545 {
546 mutt_debug(LL_DEBUG1, "Error allocating GSASL connection\n");
547 return SMTP_AUTH_UNAVAIL;
548 }
549
550 if (OptGui)
551 mutt_message(_("Authenticating (%s)..."), chosen_mech);
552
553 input_buf = buf_pool_get();
554 output_buf = buf_pool_get();
555 smtp_response_buf = buf_pool_get();
556
557 buf_printf(output_buf, "AUTH %s", chosen_mech);
558
559 /* Work around broken SMTP servers. See Debian #1010658.
560 * The msmtp source also forces IR for PLAIN because the author
561 * encountered difficulties with a server requiring it. */
562 if (mutt_str_equal(chosen_mech, "PLAIN"))
563 {
564 first_response = false;
565 char *gsasl_step_output = NULL;
566 gsasl_rc = gsasl_step64(gsasl_session, "", &gsasl_step_output);
567 if (gsasl_rc != GSASL_NEEDS_MORE && gsasl_rc != GSASL_OK)
568 {
569 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
570 gsasl_strerror(gsasl_rc));
571 goto fail;
572 }
573
574 buf_addch(output_buf, ' ');
575 buf_addstr(output_buf, gsasl_step_output);
576 gsasl_free(gsasl_step_output);
577 }
578
579 buf_addstr(output_buf, "\r\n");
580
581 do
582 {
583 if (mutt_socket_send(adata->conn, buf_string(output_buf)) < 0)
584 goto fail;
585
586 if (smtp_get_auth_response(adata->conn, input_buf, &smtp_rc, smtp_response_buf) < 0)
587 goto fail;
588
589 if (smtp_rc != SMTP_READY)
590 break;
591
592 /* Another workaround for broken SMTP servers. Instead of an
593 * empty challenge, some MS servers return a meaningless
594 * non-BASE64 encoded response in the initial reply, e.g. "334
595 * GSSAPI supported".
596 */
597 if (first_response)
598 {
599 first_response = false;
600 /* Use input_buf as a temp buffer. We've already processed the input */
601 if (mutt_b64_buffer_decode(input_buf, buf_string(smtp_response_buf)) < 0)
602 buf_reset(smtp_response_buf);
603 }
604
605 char *gsasl_step_output = NULL;
606 gsasl_rc = gsasl_step64(gsasl_session, buf_string(smtp_response_buf), &gsasl_step_output);
607 if ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK))
608 {
609 buf_strcpy(output_buf, gsasl_step_output);
610 buf_addstr(output_buf, "\r\n");
611 gsasl_free(gsasl_step_output);
612 }
613 else
614 {
615 mutt_debug(LL_DEBUG1, "gsasl_step64() failed (%d): %s\n", gsasl_rc,
616 gsasl_strerror(gsasl_rc));
617 }
618 } while ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK));
619
620 if (smtp_rc == SMTP_READY)
621 {
622 mutt_socket_send(adata->conn, "*\r\n");
623 goto fail;
624 }
625
626 if (smtp_success(smtp_rc) && (gsasl_rc == GSASL_OK))
628
629fail:
630 buf_pool_release(&input_buf);
631 buf_pool_release(&output_buf);
632 buf_pool_release(&smtp_response_buf);
633 mutt_gsasl_client_finish(&gsasl_session);
634
635 if (rc == SMTP_AUTH_FAIL)
636 mutt_debug(LL_DEBUG2, "%s failed\n", chosen_mech);
637
638 return rc;
639}
640#endif
641
642#ifdef USE_SASL_CYRUS
650static int smtp_auth_sasl(struct SmtpAccountData *adata, const char *mechlist)
651{
652 sasl_conn_t *saslconn = NULL;
653 sasl_interact_t *interaction = NULL;
654 const char *mech = NULL;
655 const char *data = NULL;
656 unsigned int data_len = 0;
657 struct Buffer *temp_buf = NULL;
658 struct Buffer *output_buf = NULL;
659 struct Buffer *smtp_response_buf = NULL;
660 int rc = SMTP_AUTH_FAIL;
661 int rc_sasl;
662 int rc_smtp;
663
664 if (mutt_sasl_client_new(adata->conn, &saslconn) < 0)
665 return SMTP_AUTH_FAIL;
666
667 /* Perform SASL client handshake: start negotiation with the server,
668 * handling any interactive prompts from the SASL library */
669 do
670 {
671 rc_sasl = sasl_client_start(saslconn, mechlist, &interaction, &data, &data_len, &mech);
672 if (rc_sasl == SASL_INTERACT)
673 mutt_sasl_interact(interaction);
674 } while (rc_sasl == SASL_INTERACT);
675
676 if ((rc_sasl != SASL_OK) && (rc_sasl != SASL_CONTINUE))
677 {
678 mutt_debug(LL_DEBUG2, "%s unavailable\n", NONULL(mech));
679 sasl_dispose(&saslconn);
680 return SMTP_AUTH_UNAVAIL;
681 }
682
683 if (OptGui)
684 {
685 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
686 mutt_message(_("Authenticating (%s)..."), mech);
687 }
688
689 /* Build the initial AUTH command, optionally including the first
690 * base64-encoded SASL response as part of the AUTH line */
691 temp_buf = buf_pool_get();
692 output_buf = buf_pool_get();
693 smtp_response_buf = buf_pool_get();
694
695 buf_printf(output_buf, "AUTH %s", mech);
696 if (data_len > 0)
697 {
698 buf_addch(output_buf, ' ');
699 mutt_b64_buffer_encode(temp_buf, data, data_len);
700 buf_addstr(output_buf, buf_string(temp_buf));
701 }
702 buf_addstr(output_buf, "\r\n");
703
704 /* Main SASL challenge/response loop: send base64-encoded data to the
705 * server, decode its response, and pass it to sasl_client_step() */
706 do
707 {
708 if (mutt_socket_send(adata->conn, buf_string(output_buf)) < 0)
709 goto fail;
710
711 if (smtp_get_auth_response(adata->conn, temp_buf, &rc_smtp, smtp_response_buf) < 0)
712 goto fail;
713
714 if (rc_smtp != SMTP_READY)
715 break;
716
717 if (mutt_b64_buffer_decode(temp_buf, buf_string(smtp_response_buf)) < 0)
718 {
719 mutt_debug(LL_DEBUG1, "error base64-decoding server response\n");
720 goto fail;
721 }
722
723 do
724 {
725 rc_sasl = sasl_client_step(saslconn, buf_string(temp_buf), buf_len(temp_buf),
726 &interaction, &data, &data_len);
727 if (rc_sasl == SASL_INTERACT)
728 mutt_sasl_interact(interaction);
729 } while (rc_sasl == SASL_INTERACT);
730
731 if (data_len > 0)
732 mutt_b64_buffer_encode(output_buf, data, data_len);
733 else
734 buf_reset(output_buf);
735
736 buf_addstr(output_buf, "\r\n");
737 } while (rc_sasl != SASL_FAIL);
738
739 /* Check final SMTP result and set up SASL security layer on success */
740 if (smtp_success(rc_smtp))
741 {
742 mutt_sasl_setup_conn(adata->conn, saslconn);
744 }
745 else
746 {
747 if (rc_smtp == SMTP_READY)
748 mutt_socket_send(adata->conn, "*\r\n");
749 sasl_dispose(&saslconn);
750 }
751
752fail:
753 buf_pool_release(&temp_buf);
754 buf_pool_release(&output_buf);
755 buf_pool_release(&smtp_response_buf);
756 return rc;
757}
758#endif
759
767static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
768{
769 /* If they did not explicitly request or configure oauth then fail quietly */
770 const char *const c_smtp_oauth_refresh_command = cs_subset_string(NeoMutt->sub, "smtp_oauth_refresh_command");
771 if (!method && !c_smtp_oauth_refresh_command)
772 return SMTP_AUTH_UNAVAIL;
773
774 const char *authtype = xoauth2 ? "XOAUTH2" : "OAUTHBEARER";
775
776 // L10N: (%s) is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
777 mutt_message(_("Authenticating (%s)..."), authtype);
778
779 /* We get the access token from the smtp_oauth_refresh_command */
780 char *oauthbearer = mutt_account_getoauthbearer(&adata->conn->account, xoauth2);
781 if (!oauthbearer)
782 return SMTP_AUTH_FAIL;
783
784 struct Buffer *input_buf = buf_pool_get();
785 struct Buffer *response_buf = buf_pool_get();
786 int auth_rc = 0;
787 int rc = SMTP_AUTH_FAIL;
788
789 buf_printf(input_buf, "AUTH %s\r\n", authtype);
790 if (mutt_socket_send(adata->conn, buf_string(input_buf)) < 0)
791 goto done;
792 if ((smtp_get_auth_response(adata->conn, input_buf, &auth_rc, response_buf) < 0) ||
793 (auth_rc != SMTP_READY))
794 {
795 goto done;
796 }
797
798 buf_printf(input_buf, "%s\r\n", oauthbearer);
799 if (mutt_socket_send(adata->conn, buf_string(input_buf)) < 0)
800 goto done;
801 if (smtp_get_auth_response(adata->conn, input_buf, &auth_rc, response_buf) < 0)
802 goto done;
803
804 if (auth_rc == SMTP_READY)
805 {
806 if (mutt_b64_buffer_decode(input_buf, buf_string(response_buf)) < 0)
807 buf_copy(input_buf, response_buf);
808 // L10N: First %s is the authentication method name: OAUTHBEARER or XOAUTH2. Second is server's
809 // error message.
810 mutt_error(_("%s authentication failed: %s"), authtype, buf_string(input_buf));
811 if (mutt_socket_send(adata->conn, xoauth2 ? "\r\n" : "AQ==\r\n") < 0)
812 goto done;
813 smtp_get_auth_response(adata->conn, input_buf, &auth_rc, response_buf);
814 goto done;
815 }
816
817 if (smtp_success(auth_rc))
819
820done:
821 FREE(&oauthbearer);
822 buf_pool_release(&input_buf);
823 buf_pool_release(&response_buf);
824 return rc;
825}
826
833static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
834{
835 return smtp_auth_oauth_xoauth2(adata, method, false);
836}
837
844static int smtp_auth_xoauth2(struct SmtpAccountData *adata, const char *method)
845{
846 return smtp_auth_oauth_xoauth2(adata, method, true);
847}
848
858static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
859{
860 struct Buffer *buf = NULL;
861 struct ConnAccount *cac = &adata->conn->account;
862 int rc = -1;
863
864 /* Get username and password. Bail out of any can't be retrieved. */
865 if ((mutt_account_getuser(cac) < 0) || (mutt_account_getpass(cac) < 0))
866 goto error;
867
868 /* Build the initial client response. */
869 buf = buf_pool_get();
870 mutt_sasl_plain_msg(buf, "AUTH PLAIN", cac->user, cac->user, cac->pass);
871 buf_add_printf(buf, "\r\n");
872
873 /* Send request, receive response (with a check for OK code). */
874 if ((mutt_socket_send(adata->conn, buf_string(buf)) < 0) || smtp_get_resp(adata))
875 goto error;
876
877 rc = 0; // Auth was successful
878
879error:
880 if (rc != 0)
881 {
882 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
883 mutt_error(_("%s authentication failed"), "SASL");
884 }
885 buf_pool_release(&buf);
886 return rc;
887}
888
898static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
899{
900 char b64[1024] = { 0 };
901 char buf[1026] = { 0 };
902
903 /* Get username and password. Bail out of any can't be retrieved. */
904 if ((mutt_account_getuser(&adata->conn->account) < 0) ||
905 (mutt_account_getpass(&adata->conn->account) < 0))
906 {
907 goto error;
908 }
909
910 /* Send the AUTH LOGIN request. */
911 if (mutt_socket_send(adata->conn, "AUTH LOGIN\r\n") < 0)
912 {
913 goto error;
914 }
915
916 /* Read the 334 VXNlcm5hbWU6 challenge ("Username:" base64-encoded) */
917 int rc = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
918 if ((rc < 0) || !mutt_str_equal(buf, "334 VXNlcm5hbWU6"))
919 {
920 goto error;
921 }
922
923 /* Send the username */
924 size_t len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.user);
925 mutt_b64_encode(buf, len, b64, sizeof(b64));
926 snprintf(buf, sizeof(buf), "%s\r\n", b64);
927 if (mutt_socket_send(adata->conn, buf) < 0)
928 {
929 goto error;
930 }
931
932 /* Read the 334 UGFzc3dvcmQ6 challenge ("Password:" base64-encoded) */
933 rc = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
934 if ((rc < 0) || !mutt_str_equal(buf, "334 UGFzc3dvcmQ6"))
935 {
936 goto error;
937 }
938
939 /* Send the password */
940 len = snprintf(buf, sizeof(buf), "%s", adata->conn->account.pass);
941 mutt_b64_encode(buf, len, b64, sizeof(b64));
942 snprintf(buf, sizeof(buf), "%s\r\n", b64);
943 if (mutt_socket_send(adata->conn, buf) < 0)
944 {
945 goto error;
946 }
947
948 /* Check the final response */
949 if (smtp_get_resp(adata) < 0)
950 {
951 goto error;
952 }
953
954 /* If we got here, auth was successful. */
955 return 0;
956
957error:
958 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
959 mutt_error(_("%s authentication failed"), "LOGIN");
960 return -1;
961}
962
966static const struct SmtpAuth SmtpAuthenticators[] = {
967 // clang-format off
968 { smtp_auth_oauth, "oauthbearer" },
969 { smtp_auth_xoauth2, "xoauth2" },
970 { smtp_auth_plain, "plain" },
971 { smtp_auth_login, "login" },
972#ifdef USE_SASL_CYRUS
973 { smtp_auth_sasl, NULL },
974#endif
975#ifdef USE_SASL_GNU
976 { smtp_auth_gsasl, NULL },
977#endif
978 // clang-format on
979};
980
989bool smtp_auth_is_valid(const char *authenticator)
990{
991 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
992 {
993 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
994 if (auth->method && mutt_istr_equal(auth->method, authenticator))
995 return true;
996 }
997
998 return false;
999}
1000
1007static int smtp_authenticate(struct SmtpAccountData *adata)
1008{
1009 int r = SMTP_AUTH_UNAVAIL;
1010
1011 const struct Slist *c_smtp_authenticators = cs_subset_slist(adata->sub, "smtp_authenticators");
1012 if (c_smtp_authenticators && (c_smtp_authenticators->count > 0))
1013 {
1014 mutt_debug(LL_DEBUG2, "Trying user-defined smtp_authenticators\n");
1015
1016 /* Try user-specified list of authentication methods */
1017 struct ListNode *np = NULL;
1018 STAILQ_FOREACH(np, &c_smtp_authenticators->head, entries)
1019 {
1020 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
1021
1022 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
1023 {
1024 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
1025 if (!auth->method || mutt_istr_equal(auth->method, np->data))
1026 {
1027 r = auth->authenticate(adata, np->data);
1028 if (r == SMTP_AUTH_SUCCESS)
1029 return r;
1030 }
1031 }
1032 }
1033 }
1034 else
1035 {
1036 /* Fall back to default: any authenticator */
1037#if defined(USE_SASL_CYRUS)
1038 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_sasl, if using sasl\n");
1039 r = smtp_auth_sasl(adata, adata->auth_mechs);
1040#elif defined(USE_SASL_GNU)
1041 mutt_debug(LL_DEBUG2, "Falling back to smtp_auth_gsasl, if using gsasl\n");
1042 r = smtp_auth_gsasl(adata, adata->auth_mechs);
1043#else
1044 mutt_debug(LL_DEBUG2, "Falling back to using any authenticator available\n");
1045 /* Try all available authentication methods */
1046 for (size_t i = 0; i < countof(SmtpAuthenticators); i++)
1047 {
1048 const struct SmtpAuth *auth = &SmtpAuthenticators[i];
1049 mutt_debug(LL_DEBUG2, "Trying method %s\n", auth->method ? auth->method : "<variable>");
1050 r = auth->authenticate(adata, auth->method);
1051 if (r == SMTP_AUTH_SUCCESS)
1052 return r;
1053 }
1054#endif
1055 }
1056
1057 if (r != SMTP_AUTH_SUCCESS)
1059
1060 if (r == SMTP_AUTH_FAIL)
1061 {
1062 // L10N: %s is the method name, e.g. Anonymous, CRAM-MD5, GSSAPI, SASL
1063 mutt_error(_("%s authentication failed"), "SASL");
1064 }
1065 else if (r == SMTP_AUTH_UNAVAIL)
1066 {
1067 mutt_error(_("No authenticators available"));
1068 }
1069
1070 return (r == SMTP_AUTH_SUCCESS) ? 0 : -1;
1071}
1072
1080static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
1081{
1082 int rc;
1083
1084 if (mutt_socket_open(adata->conn))
1085 return -1;
1086
1087 const bool force_auth = cs_subset_string(adata->sub, "smtp_user");
1088 esmtp |= force_auth;
1089
1090 /* get greeting string */
1091 rc = smtp_get_resp(adata);
1092 if (rc != 0)
1093 return rc;
1094
1095 rc = smtp_helo(adata, esmtp);
1096 if (rc != 0)
1097 return rc;
1098
1099#ifdef USE_SSL
1100 const bool c_ssl_force_tls = cs_subset_bool(adata->sub, "ssl_force_tls");
1101 enum QuadOption ans = MUTT_NO;
1102 if (adata->conn->ssf != 0)
1103 ans = MUTT_NO;
1104 else if (c_ssl_force_tls)
1105 ans = MUTT_YES;
1106 else if ((adata->capabilities & SMTP_CAP_STARTTLS) &&
1107 ((ans = query_quadoption(_("Secure connection with TLS?"),
1108 adata->sub, "ssl_starttls")) == MUTT_ABORT))
1109 {
1110 return -1;
1111 }
1112
1113 if (ans == MUTT_YES)
1114 {
1115 if (mutt_socket_send(adata->conn, "STARTTLS\r\n") < 0)
1116 return SMTP_ERR_WRITE;
1117 rc = smtp_get_resp(adata);
1118 // Clear any data after the STARTTLS acknowledgement
1119 mutt_socket_empty(adata->conn);
1120 if (rc != 0)
1121 return rc;
1122
1123 if (mutt_ssl_starttls(adata->conn) != 0)
1124 {
1125 mutt_error(_("Could not negotiate TLS connection"));
1126 return -1;
1127 }
1128
1129 /* re-EHLO to get authentication mechanisms */
1130 rc = smtp_helo(adata, esmtp);
1131 if (rc != 0)
1132 return rc;
1133 }
1134#endif
1135
1136 if (force_auth || adata->conn->account.flags & MUTT_ACCT_USER)
1137 {
1138 if (!(adata->capabilities & SMTP_CAP_AUTH))
1139 {
1140 mutt_error(_("SMTP server does not support authentication"));
1141 return -1;
1142 }
1143
1144 return smtp_authenticate(adata);
1145 }
1146
1147 return 0;
1148}
1149
1162int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to,
1163 const struct AddressList *cc, const struct AddressList *bcc,
1164 const char *msgfile, bool eightbit, struct ConfigSubset *sub)
1165{
1166 struct SmtpAccountData adata = { 0 };
1167 struct ConnAccount cac = { { 0 } };
1168 const char *envfrom = NULL;
1169 int rc = -1;
1170
1171 adata.sub = sub;
1172 adata.fqdn = mutt_fqdn(false, adata.sub);
1173 if (!adata.fqdn)
1174 adata.fqdn = NONULL(ShortHostname);
1175
1176 const struct Address *c_envelope_from_address = cs_subset_address(adata.sub, "envelope_from_address");
1177
1178 if (smtp_fill_account(&adata, &cac) < 0)
1179 return rc;
1180
1181 adata.conn = mutt_conn_find(&cac);
1182 if (!adata.conn)
1183 return -1;
1184
1185 /* it might be better to synthesize an envelope from from user and host
1186 * but this condition is most likely arrived at accidentally */
1187 if (c_envelope_from_address)
1188 {
1189 envfrom = buf_string(c_envelope_from_address->mailbox);
1190 }
1191 else if (from && !TAILQ_EMPTY(from))
1192 {
1193 envfrom = buf_string(TAILQ_FIRST(from)->mailbox);
1194 }
1195 else
1196 {
1197 mutt_error(_("No from address given"));
1198 mutt_socket_close(adata.conn);
1199 return -1;
1200 }
1201
1202 const char *const c_dsn_return = cs_subset_string(adata.sub, "dsn_return");
1203
1204 struct Buffer *buf = buf_pool_get();
1205 do
1206 {
1207 /* send our greeting */
1208 rc = smtp_open(&adata, eightbit);
1209 if (rc != 0)
1210 break;
1211 FREE(&adata.auth_mechs);
1212
1213 /* send the sender's address */
1214 buf_printf(buf, "MAIL FROM:<%s>", envfrom);
1215 if (eightbit && (adata.capabilities & SMTP_CAP_EIGHTBITMIME))
1216 buf_addstr(buf, " BODY=8BITMIME");
1217
1218 if (c_dsn_return && (adata.capabilities & SMTP_CAP_DSN))
1219 buf_add_printf(buf, " RET=%s", c_dsn_return);
1220
1221 if ((adata.capabilities & SMTP_CAP_SMTPUTF8) &&
1224 {
1225 buf_addstr(buf, " SMTPUTF8");
1226 }
1227 buf_addstr(buf, "\r\n");
1228 if (mutt_socket_send(adata.conn, buf_string(buf)) == -1)
1229 {
1230 rc = SMTP_ERR_WRITE;
1231 break;
1232 }
1233 rc = smtp_get_resp(&adata);
1234 if (rc != 0)
1235 break;
1236
1237 /* send the recipient list */
1238 if ((rc = smtp_rcpt_to(&adata, to)) || (rc = smtp_rcpt_to(&adata, cc)) ||
1239 (rc = smtp_rcpt_to(&adata, bcc)))
1240 {
1241 break;
1242 }
1243
1244 /* send the message data */
1245 rc = smtp_data(&adata, msgfile);
1246 if (rc != 0)
1247 break;
1248
1249 mutt_socket_send(adata.conn, "QUIT\r\n");
1250
1251 rc = 0;
1252 } while (false);
1253
1254 mutt_socket_close(adata.conn);
1255 FREE(&adata.conn);
1256 FREE(&adata.auth_mechs);
1257
1258 if (rc == SMTP_ERR_READ)
1259 mutt_error(_("SMTP session failed: read error"));
1260 else if (rc == SMTP_ERR_WRITE)
1261 mutt_error(_("SMTP session failed: write error"));
1262 else if (rc == SMTP_ERR_CODE)
1263 mutt_error(_("Invalid server response"));
1264
1265 buf_pool_release(&buf);
1266 return rc;
1267}
bool mutt_addrlist_uses_unicode(const struct AddressList *al)
Do any of a list of addresses use Unicode characters.
Definition address.c:1536
bool mutt_addr_uses_unicode(const char *str)
Does this address use Unicode character.
Definition address.c:1516
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:154
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:249
int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
Convert NUL-terminated base64 string to raw bytes.
Definition base64.c:267
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:168
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:211
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:497
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:89
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:674
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:248
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:401
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:607
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:99
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:1433
#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:1176
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:844
static int smtp_auth_login(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text - Implements SmtpAuth::authenticate() -.
Definition smtp.c:898
static int smtp_auth_plain(struct SmtpAccountData *adata, const char *method)
Authenticate using plain text - Implements SmtpAuth::authenticate() -.
Definition smtp.c:858
static int smtp_auth_oauth(struct SmtpAccountData *adata, const char *method)
Authenticate an SMTP connection using OAUTHBEARER - Implements SmtpAuth::authenticate() -.
Definition smtp.c:833
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:92
#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:678
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:666
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:795
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:710
int mutt_sasl_client_new(struct Connection *conn, sasl_conn_t **saslconn)
Wrapper for sasl_client_new().
Definition sasl.c:612
void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn)
Set up an SASL connection.
Definition sasl.c:746
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:718
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:1007
#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:989
static int smtp_auth_oauth_xoauth2(struct SmtpAccountData *adata, const char *method, bool xoauth2)
Authenticate an SMTP connection using OAUTHBEARER/XOAUTH2.
Definition smtp.c:767
static int smtp_get_auth_response(struct Connection *conn, struct Buffer *input_buf, int *smtp_rc, struct Buffer *response_buf)
Get the SMTP authorisation response.
Definition smtp.c:489
static const struct SmtpAuth SmtpAuthenticators[]
Accepted authentication methods.
Definition smtp.c:966
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
static int smtp_code(const struct Buffer *buf, int *n)
Extract an SMTP return code from a string.
Definition smtp.c:459
#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:1162
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:1080
#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:37
char * data
Pointer to data.
Definition buffer.h:38
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:247
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