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 #ifdef HAVE_CONFIG_H 18 # include <config.h> 19 #endif 20 21 #include <errno.h> 22 #include <stdlib.h> 23 #include <mailutils/errno.h> 24 #include <mailutils/cctype.h> 25 #include <mailutils/list.h> 26 #include <mailutils/smtp.h> 27 #include <mailutils/sys/smtp.h> 28 29 int mu_smtp_open(mu_smtp_t smtp)30mu_smtp_open (mu_smtp_t smtp) 31 { 32 int status; 33 34 if (!smtp) 35 return EINVAL; 36 if (smtp->state != MU_SMTP_INIT) 37 return MU_ERR_SEQ; 38 status = mu_smtp_response (smtp); 39 MU_SMTP_CHECK_ERROR (smtp, status); 40 if (smtp->replcode[0] != '2') 41 /* There's no use doing anything in this session, so we set the 42 _MU_SMTP_ERR flag. */ 43 MU_SMTP_CHECK_ERROR (smtp, MU_ERR_REPLY); 44 smtp->state = MU_SMTP_EHLO; 45 return 0; 46 } 47 48