1 /* GNU Mailutils -- a suite of utilities for electronic mail 2 Copyright (C) 2010-2021 Free Software Foundation, Inc. 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as published by 6 the Free Software Foundation; either version 3, or (at your option) 7 any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public License 15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifndef _MAILUTILS_SYS_SMTP_H 18 # define _MAILUTILS_SYS_SMTP_H 19 20 # include <sys/types.h> 21 # include <sys/socket.h> 22 # include <mailutils/types.h> 23 # include <mailutils/smtp.h> 24 # include <mailutils/stream.h> 25 26 # define _MU_SMTP_ESMTP 0x01 /* Connection supports ESMTP */ 27 # define _MU_SMTP_TRACE 0x02 /* Session trace required/enabled */ 28 # define _MU_SMTP_ERR 0x04 /* Object in error state */ 29 # define _MU_SMTP_MLREPL 0x08 /* Last reply was multi-line */ 30 # define _MU_SMTP_TLS 0x10 /* TLS initiated */ 31 # define _MU_SMTP_AUTH 0x20 /* Authorization passed */ 32 # define _MU_SMTP_CLNPASS 0x40 /* Password has been de-obfuscated */ 33 # define _MU_SMTP_SAVEBUF 0x80 /* Buffering state saved */ 34 35 #define MU_SMTP_XSCRIPT_MASK(n) (0x100<<(n)) 36 37 enum mu_smtp_state 38 { 39 MU_SMTP_INIT, 40 MU_SMTP_EHLO, 41 MU_SMTP_MAIL, 42 MU_SMTP_RCPT, 43 MU_SMTP_MORE, 44 MU_SMTP_DOT, 45 MU_SMTP_QUIT, 46 MU_SMTP_CLOS 47 }; 48 49 struct _mu_smtp 50 { 51 int flags; 52 53 mu_stream_t carrier; 54 enum mu_smtp_state state; 55 mu_list_t capa; 56 mu_list_t authimpl; /* List of implemented authentication mechs */ 57 58 /* User-supplied data */ 59 char *param[MU_SMTP_MAX_PARAM]; 60 mu_url_t url; 61 mu_list_t authmech; /* List of allowed authentication mechs */ 62 mu_secret_t secret; 63 64 /* I/O buffers */ 65 char replcode[4]; 66 char *replptr; 67 68 char *rdbuf; 69 size_t rdsize; 70 71 char *flbuf; 72 size_t flsize; 73 74 mu_list_t mlrepl; 75 struct mu_buffer_query savebuf; 76 }; 77 78 #define MU_SMTP_FSET(p,f) ((p)->flags |= (f)) 79 #define MU_SMTP_FISSET(p,f) ((p)->flags & (f)) 80 #define MU_SMTP_FCLR(p,f) ((p)->flags &= ~(f)) 81 82 #define MU_SMTP_CHECK_ERROR(smtp, status) \ 83 do \ 84 { \ 85 if (status != 0) \ 86 { \ 87 smtp->flags |= _MU_SMTP_ERR; \ 88 return status; \ 89 } \ 90 } \ 91 while (0) 92 93 int _mu_smtp_trace_enable (mu_smtp_t smtp); 94 int _mu_smtp_trace_disable (mu_smtp_t smtp); 95 int _mu_smtp_xscript_level (mu_smtp_t smtp, int xlev); 96 int _mu_smtp_gsasl_auth (mu_smtp_t smtp); 97 int _mu_smtp_mech_impl (mu_smtp_t smtp, mu_list_t list); 98 int _mu_smtp_data_begin (mu_smtp_t smtp); 99 int _mu_smtp_data_end (mu_smtp_t smtp); 100 101 int _mu_smtp_get_streams (mu_smtp_t smtp, mu_stream_t *streams); 102 int _mu_smtp_set_streams (mu_smtp_t smtp, mu_stream_t *streams); 103 104 105 #endif 106