NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
smtp.h File Reference
#include "config.h"
#include <stdbool.h>
+ Include dependency graph for smtp.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool smtp_auth_is_valid (const char *authenticator)
 Check if string is a valid smtp authentication method. More...
 
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. More...
 

Detailed Description

Send email to an SMTP server

Authors
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file smtp.h.

Function Documentation

◆ smtp_auth_is_valid()

bool smtp_auth_is_valid ( const char *  authenticator)

Check if string is a valid smtp authentication method.

Parameters
authenticatorAuthenticator string to check
Return values
boolTrue if argument is a valid auth method

Validate whether an input string is an accepted smtp authentication method as defined by smtp_authenticators.

Definition at line 717 of file smtp.c.

718 {
719  for (size_t i = 0; i < mutt_array_size(smtp_authenticators); i++)
720  {
721  const struct SmtpAuth *auth = &smtp_authenticators[i];
722  if (auth->method && mutt_istr_equal(auth->method, authenticator))
723  return true;
724  }
725 
726  return false;
727 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_smtp_send()

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.

Parameters
fromFrom Address
toTo Address
ccCc Address
bccBcc Address
msgfileMessage to send to the server
eightbitIf true, try for an 8-bit friendly connection
subConfig Subset
Return values
0Success
-1Error

Definition at line 880 of file smtp.c.

883 {
884  struct SmtpAccountData adata = { 0 };
885  struct ConnAccount cac = { { 0 } };
886  const char *envfrom = NULL;
887  char buf[1024];
888  int rc = -1;
889 
890  adata.sub = sub;
891  adata.fqdn = mutt_fqdn(false, adata.sub);
892  if (!adata.fqdn)
893  adata.fqdn = NONULL(ShortHostname);
894 
895  const struct Address *c_envelope_from_address =
896  cs_subset_address(adata.sub, "envelope_from_address");
897 
898  /* it might be better to synthesize an envelope from from user and host
899  * but this condition is most likely arrived at accidentally */
900  if (c_envelope_from_address)
901  envfrom = c_envelope_from_address->mailbox;
902  else if (from && !TAILQ_EMPTY(from))
903  envfrom = TAILQ_FIRST(from)->mailbox;
904  else
905  {
906  mutt_error(_("No from address given"));
907  return -1;
908  }
909 
910  if (smtp_fill_account(&adata, &cac) < 0)
911  return rc;
912 
913  adata.conn = mutt_conn_find(&cac);
914  if (!adata.conn)
915  return -1;
916 
917  const char *c_dsn_return = cs_subset_string(adata.sub, "dsn_return");
918 
919  do
920  {
921  /* send our greeting */
922  rc = smtp_open(&adata, eightbit);
923  if (rc != 0)
924  break;
925  FREE(&adata.auth_mechs);
926 
927  /* send the sender's address */
928  int len = snprintf(buf, sizeof(buf), "MAIL FROM:<%s>", envfrom);
929  if (eightbit && (adata.capabilities & SMTP_CAP_EIGHTBITMIME))
930  {
931  mutt_strn_cat(buf, sizeof(buf), " BODY=8BITMIME", 15);
932  len += 14;
933  }
934  if (c_dsn_return && (adata.capabilities & SMTP_CAP_DSN))
935  len += snprintf(buf + len, sizeof(buf) - len, " RET=%s", c_dsn_return);
936  if ((adata.capabilities & SMTP_CAP_SMTPUTF8) &&
939  {
940  snprintf(buf + len, sizeof(buf) - len, " SMTPUTF8");
941  }
942  mutt_strn_cat(buf, sizeof(buf), "\r\n", 3);
943  if (mutt_socket_send(adata.conn, buf) == -1)
944  {
945  rc = SMTP_ERR_WRITE;
946  break;
947  }
948  rc = smtp_get_resp(&adata);
949  if (rc != 0)
950  break;
951 
952  /* send the recipient list */
953  if ((rc = smtp_rcpt_to(&adata, to)) || (rc = smtp_rcpt_to(&adata, cc)) ||
954  (rc = smtp_rcpt_to(&adata, bcc)))
955  {
956  break;
957  }
958 
959  /* send the message data */
960  rc = smtp_data(&adata, msgfile);
961  if (rc != 0)
962  break;
963 
964  mutt_socket_send(adata.conn, "QUIT\r\n");
965 
966  rc = 0;
967  } while (false);
968 
969  mutt_socket_close(adata.conn);
970  FREE(&adata.conn);
971 
972  if (rc == SMTP_ERR_READ)
973  mutt_error(_("SMTP session failed: read error"));
974  else if (rc == SMTP_ERR_WRITE)
975  mutt_error(_("SMTP session failed: write error"));
976  else if (rc == SMTP_ERR_CODE)
977  mutt_error(_("Invalid server response"));
978 
979  return rc;
980 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:
ConnAccount
Login details for a remote server.
Definition: connaccount.h:51
SmtpAccountData::fqdn
const char * fqdn
Fully-qualified domain name.
Definition: smtp.c:99
SmtpAccountData::auth_mechs
const char * auth_mechs
Allowed authorisation mechanisms.
Definition: smtp.c:95
_
#define _(a)
Definition: message.h:28
NONULL
#define NONULL(x)
Definition: string2.h:37
SMTP_ERR_WRITE
#define SMTP_ERR_WRITE
Definition: smtp.c:65
TAILQ_EMPTY
#define TAILQ_EMPTY(head)
Definition: queue.h:714
mutt_socket_close
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:96
SmtpAccountData
Server connection data.
Definition: smtp.c:93
FREE
#define FREE(x)
Definition: memory.h:40
SmtpAuth
SMTP authentication multiplexor.
Definition: smtp.c:105
smtp_data
static int smtp_data(struct SmtpAccountData *adata, const char *msgfile)
Send data to an SMTP server.
Definition: smtp.c:234
SMTP_CAP_DSN
#define SMTP_CAP_DSN
Server supports Delivery Status Notification.
Definition: smtp.c:83
mutt_array_size
#define mutt_array_size(x)
Definition: memory.h:33
mutt_istr_equal
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
smtp_fill_account
static int smtp_fill_account(struct SmtpAccountData *adata, struct ConnAccount *cac)
Create ConnAccount object from SMTP Url.
Definition: smtp.c:346
mutt_strn_cat
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:414
SMTP_CAP_EIGHTBITMIME
#define SMTP_CAP_EIGHTBITMIME
Server supports 8-bit MIME content.
Definition: smtp.c:84
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:716
cs_subset_address
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:48
SmtpAuth::method
const char * method
Name of authentication method supported, NULL means variable.
Definition: smtp.c:115
SmtpAccountData::conn
struct Connection * conn
Server Connection.
Definition: smtp.c:97
SmtpAccountData::sub
struct ConfigSubset * sub
Config scope.
Definition: smtp.c:98
SmtpAccountData::capabilities
SmtpCapFlags capabilities
Server capabilities.
Definition: smtp.c:96
mutt_socket_send
#define mutt_socket_send(conn, buf)
Definition: mutt_socket.h:37
SMTP_ERR_CODE
#define SMTP_ERR_CODE
Definition: smtp.c:66
smtp_open
static int smtp_open(struct SmtpAccountData *adata, bool esmtp)
Open an SMTP Connection.
Definition: smtp.c:799
smtp_authenticators
static const struct SmtpAuth smtp_authenticators[]
Accepted authentication methods.
Definition: smtp.c:700
Address::mailbox
char * mailbox
Mailbox and host address.
Definition: address.h:37
cs_subset_string
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:241
mutt_addrlist_uses_unicode
bool mutt_addrlist_uses_unicode(const struct AddressList *al)
Do any of a list of addresses use Unicode characters.
Definition: address.c:1530
ShortHostname
WHERE char * ShortHostname
Short version of the hostname.
Definition: mutt_globals.h:50
smtp_rcpt_to
static int smtp_rcpt_to(struct SmtpAccountData *adata, const struct AddressList *al)
Set the recipient to an Address.
Definition: smtp.c:197
SMTP_CAP_SMTPUTF8
#define SMTP_CAP_SMTPUTF8
Server accepts UTF-8 strings.
Definition: smtp.c:85
mutt_fqdn
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:1182
mutt_addr_uses_unicode
bool mutt_addr_uses_unicode(const char *str)
Does this address use Unicode character.
Definition: address.c:1510
mutt_conn_find
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:86
SMTP_ERR_READ
#define SMTP_ERR_READ
Definition: smtp.c:64
smtp_get_resp
static int smtp_get_resp(struct SmtpAccountData *adata)
Read a command response from the SMTP server.
Definition: smtp.c:147
Address
An email address.
Definition: address.h:34
mutt_error
#define mutt_error(...)
Definition: logging.h:84