Commit 34128509 34128509db514024afd85a714cb9cad1f71d2d82 by Sergey Poznyakoff

Minor changes in SMTP and URL code.

* include/mailutils/smtp.h (mu_smtp_replcode)
(mu_smtp_sget_reply)
(mu_smtp_capa_iterator): New protos.
* libmailutils/url/dup.c (mu_url_dup): Bugfix. Obtain the
name using mu_url_sget_name, which will create it if necessary.
* libproto/mailer/Makefile.am (libmu_mailer_la_SOURCES): Add
smtp_capa_itr.c
* libproto/mailer/smtp_capa_itr.c: New file.
* libproto/mailer/smtp_io.c (mu_smtp_response): Fix filling of
smtp->flbuf.
(mu_smtp_replcode,mu_smtp_sget_reply): New functions.
1 parent 0b1e16be
...@@ -45,6 +45,10 @@ int mu_smtp_open (mu_smtp_t); ...@@ -45,6 +45,10 @@ int mu_smtp_open (mu_smtp_t);
45 int mu_smtp_response (mu_smtp_t smtp); 45 int mu_smtp_response (mu_smtp_t smtp);
46 int mu_smtp_write (mu_smtp_t smtp, const char *fmt, ...) MU_PRINTFLIKE(2,3); 46 int mu_smtp_write (mu_smtp_t smtp, const char *fmt, ...) MU_PRINTFLIKE(2,3);
47 47
48 int mu_smtp_replcode (mu_smtp_t smtp, char *buf);
49 int mu_smtp_sget_reply (mu_smtp_t smtp, const char **pbuf);
50
51
48 #define MU_SMTP_TRACE_CLR 0 52 #define MU_SMTP_TRACE_CLR 0
49 #define MU_SMTP_TRACE_SET 1 53 #define MU_SMTP_TRACE_SET 1
50 #define MU_SMTP_TRACE_QRY 2 54 #define MU_SMTP_TRACE_QRY 2
...@@ -61,6 +65,7 @@ int mu_smtp_set_secret (mu_smtp_t smtp, mu_secret_t secret); ...@@ -61,6 +65,7 @@ int mu_smtp_set_secret (mu_smtp_t smtp, mu_secret_t secret);
61 int mu_smtp_get_secret (mu_smtp_t smtp, mu_secret_t *secret); 65 int mu_smtp_get_secret (mu_smtp_t smtp, mu_secret_t *secret);
62 66
63 int mu_smtp_capa_test (mu_smtp_t smtp, const char *capa, const char **pret); 67 int mu_smtp_capa_test (mu_smtp_t smtp, const char *capa, const char **pret);
68 int mu_smtp_capa_iterator (mu_smtp_t smtp, mu_iterator_t *itr);
64 int mu_smtp_starttls (mu_smtp_t smtp); 69 int mu_smtp_starttls (mu_smtp_t smtp);
65 70
66 int mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, 71 int mu_smtp_mail_basic (mu_smtp_t smtp, const char *email,
......
...@@ -34,11 +34,13 @@ int ...@@ -34,11 +34,13 @@ int
34 mu_url_dup (mu_url_t old_url, mu_url_t *new_url) 34 mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
35 { 35 {
36 int rc; 36 int rc;
37 const char *s;
37 mu_url_t url = calloc (1, sizeof (*url)); 38 mu_url_t url = calloc (1, sizeof (*url));
38 39
39 if (!url) 40 if (!url)
40 return ENOMEM; 41 return ENOMEM;
41 url->name = strdup (old_url->name); 42 mu_url_sget_name (old_url, &s);
43 url->name = strdup (s);
42 if (!url->name) 44 if (!url->name)
43 { 45 {
44 free (url); 46 free (url);
......
...@@ -32,6 +32,7 @@ libmu_mailer_la_SOURCES = \ ...@@ -32,6 +32,7 @@ libmu_mailer_la_SOURCES = \
32 smtp.c\ 32 smtp.c\
33 smtp_auth.c\ 33 smtp_auth.c\
34 smtp_capa.c\ 34 smtp_capa.c\
35 smtp_capa_itr.c\
35 smtp_carrier.c\ 36 smtp_carrier.c\
36 smtp_create.c\ 37 smtp_create.c\
37 smtp_data.c\ 38 smtp_data.c\
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2010-2012 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
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 }
...@@ -89,7 +89,8 @@ mu_smtp_response (mu_smtp_t smtp) ...@@ -89,7 +89,8 @@ mu_smtp_response (mu_smtp_t smtp)
89 smtp->flbuf = p; 89 smtp->flbuf = p;
90 smtp->flsize = n; 90 smtp->flsize = n;
91 } 91 }
92 memcpy (smtp->flbuf, smtp->rdbuf + 4, n - 3); 92 memcpy (smtp->flbuf, smtp->rdbuf + 4, n - 1);
93 smtp->flbuf[n - 1] = 0;
93 smtp->replptr = smtp->flbuf; 94 smtp->replptr = smtp->flbuf;
94 95
95 rc = _mu_smtp_init_mlist (smtp); 96 rc = _mu_smtp_init_mlist (smtp);
...@@ -125,6 +126,22 @@ mu_smtp_response (mu_smtp_t smtp) ...@@ -125,6 +126,22 @@ mu_smtp_response (mu_smtp_t smtp)
125 return 0; 126 return 0;
126 } 127 }
127 128
129 int
130 mu_smtp_replcode (mu_smtp_t smtp, char *buf)
131 {
132 if (!smtp || !buf)
133 return EINVAL;
134 strcpy (buf, smtp->replcode);
135 return 0;
136 }
128 137
138 int
139 mu_smtp_sget_reply (mu_smtp_t smtp, const char **pbuf)
140 {
141 if (!smtp || !pbuf)
142 return EINVAL;
143 *pbuf = smtp->replptr;
144 return 0;
145 }
129 146
130 147
......