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/list.h>
25 #include <mailutils/iterator.h>
26 #include <mailutils/smtp.h>
27 #include <mailutils/sys/smtp.h>
28 
29 int
mu_smtp_capa_iterator(mu_smtp_t smtp,mu_iterator_t * itr)30 mu_smtp_capa_iterator (mu_smtp_t smtp, mu_iterator_t *itr)
31 {
32   if (!smtp || !itr)
33     return EINVAL;
34   if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
35     return MU_ERR_FAILURE;
36   if (!smtp->capa)
37     {
38       int rc = mu_smtp_ehlo (smtp);
39       if (rc)
40 	return rc;
41     }
42   if (!MU_SMTP_FISSET (smtp, _MU_SMTP_ESMTP))
43     return MU_ERR_FAILURE;
44   return mu_list_get_iterator (smtp->capa, itr);
45 }
46