1*91ef716eSjsg /* $OpenBSD: smtp.h,v 1.5 2024/06/02 23:26:39 jsg Exp $ */ 2ef573529Seric 3ef573529Seric /* 4ef573529Seric * Copyright (c) 2018 Eric Faurot <eric@openbsd.org> 5ef573529Seric * 6ef573529Seric * Permission to use, copy, modify, and distribute this software for any 7ef573529Seric * purpose with or without fee is hereby granted, provided that the above 8ef573529Seric * copyright notice and this permission notice appear in all copies. 9ef573529Seric * 10ef573529Seric * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11ef573529Seric * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12ef573529Seric * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13ef573529Seric * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14ef573529Seric * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15ef573529Seric * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16ef573529Seric * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17ef573529Seric */ 18ef573529Seric 19ef573529Seric #define TLS_NO 0 20ef573529Seric #define TLS_YES 1 21ef573529Seric #define TLS_FORCE 2 22ef573529Seric #define TLS_SMTPS 3 23ef573529Seric 24ef573529Seric #define CERT_OK 0 25ef573529Seric #define CERT_UNKNOWN 1 26ef573529Seric #define CERT_INVALID 2 27ef573529Seric 28ef573529Seric #define FAIL_INTERNAL 1 /* malloc, etc. (check errno) */ 29ef573529Seric #define FAIL_CONN 2 /* disconnect, timeout... (check errno) */ 30ef573529Seric #define FAIL_PROTO 3 /* protocol violation */ 31ef573529Seric #define FAIL_IMPL 4 /* server lacks a required feature */ 32ef573529Seric #define FAIL_RESP 5 /* rejected command */ 33ef573529Seric 34ef573529Seric struct smtp_params { 35ef573529Seric 36ef573529Seric /* Client options */ 37ef573529Seric size_t linemax; /* max input line size */ 38ef573529Seric size_t ibufmax; /* max input buffer size */ 39ef573529Seric size_t obufmax; /* max output buffer size */ 40ef573529Seric 41ef573529Seric /* Connection settings */ 42ef573529Seric const struct sockaddr *dst; /* address to connect to */ 43ef573529Seric const struct sockaddr *src; /* address to bind to */ 44ef573529Seric int timeout; /* timeout in seconds */ 45ef573529Seric 46ef573529Seric /* TLS options */ 47ef573529Seric int tls_req; /* requested TLS mode */ 48ef573529Seric int tls_verify; /* need valid server certificate */ 49eed85469Seric const char *tls_servname; /* SNI */ 50ef573529Seric 51ef573529Seric /* SMTP options */ 52ef573529Seric int lmtp; /* use LMTP protocol */ 53ef573529Seric const char *helo; /* string to use with HELO */ 5443ddfbdbSeric const char *auth_user; /* for AUTH */ 5543ddfbdbSeric const char *auth_pass; /* for AUTH */ 56ef573529Seric }; 57ef573529Seric 58ef573529Seric struct smtp_rcpt { 59ef573529Seric const char *to; 60ef573529Seric const char *dsn_notify; 61ef573529Seric const char *dsn_orcpt; 62ef573529Seric int done; 63ef573529Seric }; 64ef573529Seric 65ef573529Seric struct smtp_mail { 66ef573529Seric const char *from; 67ef573529Seric const char *dsn_ret; 68ef573529Seric const char *dsn_envid; 69ef573529Seric struct smtp_rcpt *rcpt; 70ef573529Seric int rcptcount; 71ef573529Seric FILE *fp; 72ef573529Seric }; 73ef573529Seric 74ef573529Seric struct smtp_status { 75ef573529Seric struct smtp_rcpt *rcpt; 76ef573529Seric const char *cmd; 77ef573529Seric const char *status; 78ef573529Seric }; 79ef573529Seric 80ef573529Seric struct smtp_client; 81ef573529Seric 82ef573529Seric /* smtp_client.c */ 83ef573529Seric struct smtp_client *smtp_connect(const struct smtp_params *, void *); 84ef573529Seric void smtp_cert_verified(struct smtp_client *, int); 85cde53503Seric void smtp_set_tls(struct smtp_client *, void *); 86ef573529Seric void smtp_quit(struct smtp_client *); 87ef573529Seric void smtp_sendmail(struct smtp_client *, struct smtp_mail *); 88ef573529Seric 89ef573529Seric /* callbacks */ 90cde53503Seric void smtp_require_tls(void *, struct smtp_client *); 91ef573529Seric void smtp_ready(void *, struct smtp_client *); 92ef573529Seric void smtp_failed(void *, struct smtp_client *, int, const char *); 93ef573529Seric void smtp_closed(void *, struct smtp_client *); 94ef573529Seric void smtp_status(void *, struct smtp_client *, struct smtp_status *); 95ef573529Seric void smtp_done(void *, struct smtp_client *, struct smtp_mail *); 96