1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 3 of the License, or (at your option) 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 GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General
15    Public License along with this library  If not, see
16    <http://www.gnu.org/licenses/>. */
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <string.h>
27 
28 #include <mailutils/sys/registrar.h>
29 #include <mailutils/sys/url.h>
30 #include <mailutils/sys/imap.h>
31 #include <mailutils/util.h>
32 
33 static void url_imap_destroy (mu_url_t url);
34 
35 static void
url_imap_destroy(mu_url_t url MU_ARG_UNUSED)36 url_imap_destroy (mu_url_t url MU_ARG_UNUSED)
37 {
38 }
39 
40 static int
url_imap_get_path(const mu_url_t url,char * bufptr,size_t bufsize,size_t * rsize)41 url_imap_get_path (const mu_url_t url, char *bufptr, size_t bufsize,
42 		   size_t *rsize)
43 {
44   bufsize = mu_cpystr (bufptr, "INBOX", bufsize);
45   if (rsize)
46     *rsize = bufsize;
47   return 0;
48 }
49 
50 /*
51   IMAP URLs:
52     imap://[<user>[;AUTH=<auth>]@]<host>[/<mailbox>]
53     imap://[<user>[:<pass>]@]<host>[/<mailbox>]
54 */
55 
56 int
_mu_imap_url_init(mu_url_t url)57 _mu_imap_url_init (mu_url_t url)
58 {
59   if (url->port == 0)
60     url->port = MU_IMAP_PORT;
61 
62   url->_destroy = url_imap_destroy;
63   url->_get_path = url_imap_get_path;
64 
65   if (!url->host || url->qargc)
66     return EINVAL;
67 
68   /* fill in default auth, if necessary */
69   if (!url->auth)
70     {
71       url->auth = malloc (1 + 1);
72       if (!url->auth)
73 	return ENOMEM;
74 
75       url->auth[0] = '*';
76       url->auth[1] = '\0';
77     }
78 
79   return 0;
80 }
81 
82 /*
83   IMAPS URLs:
84     imaps://[<user>[;AUTH=<auth>]@]<host>[/<mailbox>]
85     imaps://[<user>[:<pass>]@]<host>[/<mailbox>]
86 */
87 
88 int
_mu_imaps_url_init(mu_url_t url)89 _mu_imaps_url_init (mu_url_t url)
90 {
91   if (url->port == 0)
92     url->port = MU_IMAPS_PORT;
93 
94   url->_destroy = url_imap_destroy;
95   url->_get_path = url_imap_get_path;
96 
97   if (!url->host || url->qargc)
98     return EINVAL;
99 
100   /* fill in default auth, if necessary */
101   if (!url->auth)
102     {
103       url->auth = malloc (1 + 1);
104       if (!url->auth)
105 	return ENOMEM;
106 
107       url->auth[0] = '*';
108       url->auth[1] = '\0';
109     }
110 
111   return 0;
112 }
113 
114