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