Commit aa0debf5 aa0debf5d7f45684db96fe2a5be171ad870975ab by Sergey Poznyakoff

imap client: implement STORE, DELETE, RENAME, CHECK, EXPUNGE, COPY, CLOSE and UNSELECT.

* include/mailutils/imap.h (imap_command): New struct.
(mu_imap_gencom): New function.
(mu_imap_store,mu_imap_delete)
(mu_imap_rename,mu_imap_mailbox_close,mu_imap_close)
(mu_imap_check): New functions.
(_mu_close_handler): New function.
* include/mailutils/sys/imap.h (mu_imap_client_state): Add new states.
* libproto/imap/gencom.c: New file.
* libproto/imap/close.c: New file.
* libproto/imap/delete.c: New file.
* libproto/imap/rename.c: New file.
* libproto/imap/store.c: New file.
* libproto/imap/unselect.c: New file.
* libproto/imap/check.c: New file.
* libproto/imap/expunge.c: New file.
* libproto/imap/copy.c: New file.
* libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Add new files.

* mu/imap.c: Implement new commands.
* mu/shell.c (execute_line): Treat backslash as escape only before
another backslash or double-quote.
1 parent b12c4638
...@@ -38,13 +38,25 @@ enum mu_imap_session_state ...@@ -38,13 +38,25 @@ enum mu_imap_session_state
38 MU_IMAP_SESSION_INIT, /* Initial state (disconnected) */ 38 MU_IMAP_SESSION_INIT, /* Initial state (disconnected) */
39 MU_IMAP_SESSION_NONAUTH, /* Non-Authenticated State */ 39 MU_IMAP_SESSION_NONAUTH, /* Non-Authenticated State */
40 MU_IMAP_SESSION_AUTH, /* Authenticated State */ 40 MU_IMAP_SESSION_AUTH, /* Authenticated State */
41 MU_IMAP_SESSION_SELECTED, /* Selected State */ 41 MU_IMAP_SESSION_SELECTED /* Selected State */
42 MU_IMAP_SESSION_LOGOUT, /* Logout State */
43 }; 42 };
44 43
45 int mu_imap_create (mu_imap_t *pimap); 44 int mu_imap_create (mu_imap_t *pimap);
46 void mu_imap_destroy (mu_imap_t *pimap); 45 void mu_imap_destroy (mu_imap_t *pimap);
47 46
47 struct imap_command
48 {
49 int session_state;
50 char *capa;
51 int rx_state;
52 int uid;
53 int argc;
54 char const **argv;
55 void (*handler) (mu_imap_t);
56 };
57
58 int mu_imap_gencom (mu_imap_t imap, struct imap_command *cmd);
59
48 int mu_imap_connect (mu_imap_t imap); 60 int mu_imap_connect (mu_imap_t imap);
49 int mu_imap_disconnect (mu_imap_t imap); 61 int mu_imap_disconnect (mu_imap_t imap);
50 62
...@@ -58,8 +70,23 @@ int mu_imap_logout (mu_imap_t imap); ...@@ -58,8 +70,23 @@ int mu_imap_logout (mu_imap_t imap);
58 int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc); 70 int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc);
59 71
60 int mu_imap_noop (mu_imap_t imap); 72 int mu_imap_noop (mu_imap_t imap);
73 int mu_imap_check (mu_imap_t imap);
74
75 int mu_imap_fetch (mu_imap_t imap, int uid, const char *msgset,
76 const char *items);
77 int mu_imap_store (mu_imap_t imap, int uid, const char *msgset,
78 const char *items);
79
80 int mu_imap_delete (mu_imap_t imap, const char *mailbox);
81 int mu_imap_rename (mu_imap_t imap, const char *mailbox,
82 const char *new_mailbox);
83 int mu_imap_copy (mu_imap_t imap, int uid, const char *msgset,
84 const char *mailbox);
85
86 int mu_imap_close (mu_imap_t imap);
87 int mu_imap_unselect (mu_imap_t imap);
61 88
62 int mu_imap_fetch (mu_imap_t imap, const char *msgset, const char *items); 89 int mu_imap_expunge (mu_imap_t imap);
63 90
64 int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier); 91 int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier);
65 int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier); 92 int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier);
......
...@@ -57,6 +57,14 @@ enum mu_imap_client_state ...@@ -57,6 +57,14 @@ enum mu_imap_client_state
57 MU_IMAP_CLIENT_STATUS_RX, 57 MU_IMAP_CLIENT_STATUS_RX,
58 MU_IMAP_CLIENT_NOOP_RX, 58 MU_IMAP_CLIENT_NOOP_RX,
59 MU_IMAP_CLIENT_FETCH_RX, 59 MU_IMAP_CLIENT_FETCH_RX,
60 MU_IMAP_CLIENT_STORE_RX,
61 MU_IMAP_CLIENT_DELETE_RX,
62 MU_IMAP_CLIENT_RENAME_RX,
63 MU_IMAP_CLIENT_CLOSE_RX,
64 MU_IMAP_CLIENT_UNSELECT_RX,
65 MU_IMAP_CLIENT_CHECK_RX,
66 MU_IMAP_CLIENT_COPY_RX,
67 MU_IMAP_CLIENT_EXPUNGE_RX,
60 MU_IMAP_CLIENT_CLOSING 68 MU_IMAP_CLIENT_CLOSING
61 }; 69 };
62 70
...@@ -195,6 +203,8 @@ struct imap_list_element *_mu_imap_list_at (mu_list_t list, int idx); ...@@ -195,6 +203,8 @@ struct imap_list_element *_mu_imap_list_at (mu_list_t list, int idx);
195 203
196 int _mu_imap_parse_fetch_response (mu_list_t resp, mu_list_t *result_list); 204 int _mu_imap_parse_fetch_response (mu_list_t resp, mu_list_t *result_list);
197 205
206 void _mu_close_handler (mu_imap_t imap);
207
198 # ifdef __cplusplus 208 # ifdef __cplusplus
199 } 209 }
200 # endif 210 # endif
......
...@@ -16,6 +16,7 @@ imapio ...@@ -16,6 +16,7 @@ imapio
16 listop 16 listop
17 mailcap 17 mailcap
18 prop 18 prop
19 scantime
19 strftime 20 strftime
20 url-comp 21 url-comp
21 url-parse 22 url-parse
......
...@@ -29,25 +29,34 @@ libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@ ...@@ -29,25 +29,34 @@ libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@
29 libmu_imap_la_SOURCES = \ 29 libmu_imap_la_SOURCES = \
30 fake-folder.c\ 30 fake-folder.c\
31 fetch.c\ 31 fetch.c\
32 gencom.c\
32 callback.c\ 33 callback.c\
33 capability.c\ 34 capability.c\
34 capatst.c\ 35 capatst.c\
35 carrier.c\ 36 carrier.c\
37 check.c\
38 close.c\
36 connect.c\ 39 connect.c\
40 copy.c\
37 create.c\ 41 create.c\
42 delete.c\
38 destroy.c\ 43 destroy.c\
39 disconnect.c\ 44 disconnect.c\
40 err.c\ 45 err.c\
46 expunge.c\
41 id.c\ 47 id.c\
42 login.c\ 48 login.c\
43 logout.c\ 49 logout.c\
44 noop.c\ 50 noop.c\
51 rename.c\
45 resplist.c\ 52 resplist.c\
46 response.c\ 53 response.c\
47 resproc.c\ 54 resproc.c\
48 select.c\ 55 select.c\
49 state.c\ 56 state.c\
50 status.c\ 57 status.c\
58 store.c\
51 tag.c\ 59 tag.c\
52 trace.c 60 trace.c\
61 unselect.c
53 62
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <mailutils/imap.h>
23 #include <mailutils/sys/imap.h>
24
25 int
26 mu_imap_check (mu_imap_t imap)
27 {
28 static char const *command = "CHECK";
29 static struct imap_command com = {
30 MU_IMAP_SESSION_SELECTED,
31 NULL,
32 MU_IMAP_CLIENT_CHECK_RX,
33 0,
34 1,
35 &command,
36 NULL
37 };
38 return mu_imap_gencom (imap, &com);
39 }
40
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <mailutils/imap.h>
23 #include <mailutils/sys/imap.h>
24
25 void
26 _mu_close_handler (mu_imap_t imap)
27 {
28 if (imap->resp_code == MU_IMAP_OK)
29 imap->session_state = MU_IMAP_SESSION_AUTH;
30 }
31
32 int
33 mu_imap_close (mu_imap_t imap)
34 {
35 static char const *command = "CLOSE";
36 static struct imap_command com = {
37 MU_IMAP_SESSION_SELECTED,
38 NULL,
39 MU_IMAP_CLIENT_CLOSE_RX,
40 0,
41 1,
42 &command,
43 _mu_close_handler
44 };
45 return mu_imap_gencom (imap, &com);
46 }
47
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <mailutils/errno.h>
23 #include <mailutils/imap.h>
24 #include <mailutils/sys/imap.h>
25
26 int
27 mu_imap_copy (mu_imap_t imap, int uid, const char *msgset, const char *mailbox)
28 {
29 char const *argv[3];
30 static struct imap_command com;
31
32 argv[0] = "COPY";
33 argv[1] = msgset;
34 argv[2] = mailbox;
35
36 com.session_state = MU_IMAP_SESSION_SELECTED;
37 com.capa = NULL;
38 com.rx_state = MU_IMAP_CLIENT_COPY_RX;
39 com.uid = 0;
40 com.argc = 3;
41 com.argv = argv;
42 com.handler = NULL;
43
44 return mu_imap_gencom (imap, &com);
45 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <stdlib.h>
23 #include <string.h>
24 #include <mailutils/errno.h>
25 #include <mailutils/imap.h>
26 #include <mailutils/sys/imap.h>
27
28 int
29 mu_imap_delete (mu_imap_t imap, const char *mailbox)
30 {
31 char const *argv[2];
32 static struct imap_command com;
33
34 argv[0] = "DELETE";
35 argv[1] = mailbox;
36
37 com.session_state = MU_IMAP_SESSION_AUTH;
38 com.capa = NULL;
39 com.rx_state = MU_IMAP_CLIENT_DELETE_RX;
40 com.uid = 0;
41 com.argc = 2;
42 com.argv = argv;
43 com.handler = NULL;
44
45 return mu_imap_gencom (imap, &com);
46 }
47
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <mailutils/imap.h>
23 #include <mailutils/sys/imap.h>
24
25 int
26 mu_imap_expunge (mu_imap_t imap)
27 {
28 static char const *command = "EXPUNGE";
29 static struct imap_command com = {
30 MU_IMAP_SESSION_SELECTED,
31 NULL,
32 MU_IMAP_CLIENT_EXPUNGE_RX,
33 0,
34 1,
35 &command,
36 NULL
37 };
38 return mu_imap_gencom (imap, &com);
39 }
40
...@@ -29,53 +29,24 @@ ...@@ -29,53 +29,24 @@
29 #include <mailutils/sys/imap.h> 29 #include <mailutils/sys/imap.h>
30 30
31 int 31 int
32 mu_imap_fetch (mu_imap_t imap, const char *msgset, const char *items) 32 mu_imap_fetch (mu_imap_t imap, int uid, const char *msgset, const char *items)
33 { 33 {
34 int status; 34 char const *argv[3];
35 35 static struct imap_command com;
36 if (imap == NULL) 36
37 return EINVAL; 37 argv[0] = "FETCH";
38 if (!imap->io) 38 argv[1] = msgset;
39 return MU_ERR_NO_TRANSPORT; 39 argv[2] = items;
40 40
41 if (imap->session_state != MU_IMAP_SESSION_SELECTED) 41 com.session_state = MU_IMAP_SESSION_SELECTED;
42 return MU_ERR_SEQ; 42 com.capa = NULL;
43 43 com.rx_state = MU_IMAP_CLIENT_FETCH_RX;
44 switch (imap->client_state) 44 com.uid = uid;
45 { 45 com.argc = 3;
46 case MU_IMAP_CLIENT_READY: 46 com.argv = argv;
47 status = _mu_imap_tag_next (imap); 47 com.handler = NULL;
48 MU_IMAP_CHECK_EAGAIN (imap, status); 48
49 status = mu_imapio_printf (imap->io, "%s FETCH %s %s\r\n", 49 return mu_imap_gencom (imap, &com);
50 imap->tag_str, msgset, items);
51 MU_IMAP_CHECK_ERROR (imap, status);
52 MU_IMAP_FCLR (imap, MU_IMAP_RESP);
53 imap->client_state = MU_IMAP_CLIENT_FETCH_RX;
54
55 case MU_IMAP_CLIENT_FETCH_RX:
56 status = _mu_imap_response (imap, NULL, NULL);
57 MU_IMAP_CHECK_EAGAIN (imap, status);
58 switch (imap->resp_code)
59 {
60 case MU_IMAP_OK:
61 status = 0;
62 break;
63
64 case MU_IMAP_NO:
65 status = MU_ERR_FAILURE;
66 break;
67
68 case MU_IMAP_BAD:
69 status = MU_ERR_BADREPLY;
70 break;
71 }
72 imap->client_state = MU_IMAP_CLIENT_READY;
73 break;
74
75 default:
76 status = EINPROGRESS;
77 }
78 return status;
79 } 50 }
80 51
81 static void 52 static void
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <stdlib.h>
23 #include <mailutils/errno.h>
24 #include <mailutils/imap.h>
25 #include <mailutils/sys/imap.h>
26
27 int
28 mu_imap_gencom (mu_imap_t imap, struct imap_command *cmd)
29 {
30 int status;
31 int i;
32
33 if (imap == NULL || !cmd || cmd->argc < 1)
34 return EINVAL;
35 if (!imap->io)
36 return MU_ERR_NO_TRANSPORT;
37 if (imap->session_state < cmd->session_state)
38 return MU_ERR_SEQ;
39
40 if (cmd->capa)
41 {
42 status = mu_imap_capability_test (imap, cmd->capa, NULL);
43 switch (status)
44 {
45 case 0:
46 break;
47
48 case MU_ERR_NOENT:
49 return ENOSYS;
50
51 default:
52 return status;
53 }
54 }
55
56 if (imap->client_state == MU_IMAP_CLIENT_READY)
57 {
58 status = _mu_imap_tag_next (imap);
59 MU_IMAP_CHECK_EAGAIN (imap, status);
60 status = mu_imapio_printf (imap->io, "%s", imap->tag_str);
61 if (status == 0 && cmd->uid)
62 status = mu_imapio_printf (imap->io, " UID");
63 MU_IMAP_CHECK_ERROR (imap, status);
64 for (i = 0; i < cmd->argc; i++)
65 {
66 status = mu_imapio_printf (imap->io, " %s", cmd->argv[i]);
67 MU_IMAP_CHECK_ERROR (imap, status);
68 }
69 status = mu_imapio_send (imap->io, "\r\n", 2);
70 MU_IMAP_CHECK_ERROR (imap, status);
71 MU_IMAP_FCLR (imap, MU_IMAP_RESP);
72 imap->client_state = cmd->rx_state;
73 }
74
75 if (imap->client_state == cmd->rx_state)
76 {
77 status = _mu_imap_response (imap, NULL, NULL);
78 MU_IMAP_CHECK_EAGAIN (imap, status);
79 if (cmd->handler)
80 cmd->handler (imap);
81 switch (imap->resp_code)
82 {
83 case MU_IMAP_OK:
84 status = 0;
85 break;
86
87 case MU_IMAP_NO:
88 status = MU_ERR_FAILURE;
89 break;
90
91 case MU_IMAP_BAD:
92 status = MU_ERR_BADREPLY;
93 break;
94 }
95 imap->client_state = MU_IMAP_CLIENT_READY;
96 }
97 else
98 status = EINPROGRESS;
99
100 return status;
101 }
102
...@@ -51,7 +51,7 @@ mu_imap_logout (mu_imap_t imap) ...@@ -51,7 +51,7 @@ mu_imap_logout (mu_imap_t imap)
51 status = _mu_imap_response (imap, NULL, NULL); 51 status = _mu_imap_response (imap, NULL, NULL);
52 MU_IMAP_CHECK_EAGAIN (imap, status); 52 MU_IMAP_CHECK_EAGAIN (imap, status);
53 imap->client_state = MU_IMAP_CLIENT_READY; 53 imap->client_state = MU_IMAP_CLIENT_READY;
54 imap->session_state = MU_IMAP_SESSION_LOGOUT; 54 imap->session_state = MU_IMAP_SESSION_INIT;
55 break; 55 break;
56 56
57 default: 57 default:
......
...@@ -19,56 +19,22 @@ ...@@ -19,56 +19,22 @@
19 # include <config.h> 19 # include <config.h>
20 #endif 20 #endif
21 21
22 #include <stdlib.h>
23 #include <mailutils/errno.h>
24 #include <mailutils/imap.h> 22 #include <mailutils/imap.h>
25 #include <mailutils/sys/imap.h> 23 #include <mailutils/sys/imap.h>
26 24
27 int 25 int
28 mu_imap_noop (mu_imap_t imap) 26 mu_imap_noop (mu_imap_t imap)
29 { 27 {
30 int status; 28 static char const *command = "NOOP";
31 29 static struct imap_command com = {
32 if (imap == NULL) 30 MU_IMAP_SESSION_INIT,
33 return EINVAL; 31 NULL,
34 if (!imap->io) 32 MU_IMAP_CLIENT_NOOP_RX,
35 return MU_ERR_NO_TRANSPORT; 33 0,
36 if (imap->session_state == MU_IMAP_SESSION_INIT) 34 1,
37 return MU_ERR_SEQ; 35 &command,
38 36 NULL
39 switch (imap->client_state) 37 };
40 { 38 return mu_imap_gencom (imap, &com);
41 case MU_IMAP_CLIENT_READY:
42 status = _mu_imap_tag_next (imap);
43 MU_IMAP_CHECK_EAGAIN (imap, status);
44 status = mu_imapio_printf (imap->io, "%s NOOP\r\n", imap->tag_str);
45 MU_IMAP_CHECK_ERROR (imap, status);
46 MU_IMAP_FCLR (imap, MU_IMAP_RESP);
47 imap->client_state = MU_IMAP_CLIENT_NOOP_RX;
48
49 case MU_IMAP_CLIENT_NOOP_RX:
50 status = _mu_imap_response (imap, NULL, NULL);
51 MU_IMAP_CHECK_EAGAIN (imap, status);
52 switch (imap->resp_code)
53 {
54 case MU_IMAP_OK:
55 status = 0;
56 break;
57
58 case MU_IMAP_NO:
59 status = MU_ERR_FAILURE;
60 break;
61
62 case MU_IMAP_BAD:
63 status = MU_ERR_BADREPLY;
64 break;
65 }
66 imap->client_state = MU_IMAP_CLIENT_READY;
67 break;
68
69 default:
70 status = EINPROGRESS;
71 }
72 return status;
73 } 39 }
74 40
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <mailutils/errno.h>
23 #include <mailutils/imap.h>
24 #include <mailutils/sys/imap.h>
25
26 int
27 mu_imap_rename (mu_imap_t imap, const char *mailbox, const char *new_mailbox)
28 {
29 char const *argv[3];
30 static struct imap_command com;
31
32 argv[0] = "RENAME";
33 argv[1] = mailbox;
34 argv[2] = new_mailbox;
35
36 com.session_state = MU_IMAP_SESSION_AUTH;
37 com.capa = NULL;
38 com.rx_state = MU_IMAP_CLIENT_DELETE_RX;
39 com.uid = 0;
40 com.argc = 3;
41 com.argv = argv;
42 com.handler = NULL;
43
44 return mu_imap_gencom (imap, &com);
45 }
46
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <stdlib.h>
23 #include <string.h>
24 #include <mailutils/errno.h>
25 #include <mailutils/imap.h>
26 #include <mailutils/sys/imap.h>
27
28 int
29 mu_imap_store (mu_imap_t imap, int uid, const char *msgset, const char *items)
30 {
31 char const *argv[3];
32 static struct imap_command com;
33
34 argv[0] = "STORE";
35 argv[1] = msgset;
36 argv[2] = items;
37
38 com.session_state = MU_IMAP_SESSION_SELECTED;
39 com.capa = NULL;
40 com.rx_state = MU_IMAP_CLIENT_STORE_RX;
41 com.uid = uid;
42 com.argc = 3;
43 com.argv = argv;
44 com.handler = NULL;
45
46 return mu_imap_gencom (imap, &com);
47 }
48
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 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 <mailutils/imap.h>
23 #include <mailutils/sys/imap.h>
24
25 int
26 mu_imap_unselect (mu_imap_t imap)
27 {
28 static char const *command = "UNSELECT";
29 static struct imap_command com = {
30 MU_IMAP_SESSION_SELECTED,
31 NULL,
32 MU_IMAP_CLIENT_UNSELECT_RX,
33 0,
34 1,
35 &command,
36 _mu_close_handler
37 };
38 return mu_imap_gencom (imap, &com);
39 }
40
...@@ -69,11 +69,7 @@ current_imap_state () ...@@ -69,11 +69,7 @@ current_imap_state ()
69 if (imap == NULL) 69 if (imap == NULL)
70 state = MU_IMAP_SESSION_INIT; 70 state = MU_IMAP_SESSION_INIT;
71 else 71 else
72 {
73 mu_imap_state (imap, &state); 72 mu_imap_state (imap, &state);
74 if (state == MU_IMAP_SESSION_LOGOUT)
75 state = MU_IMAP_SESSION_INIT;
76 }
77 return state; 73 return state;
78 } 74 }
79 75
...@@ -731,6 +727,15 @@ com_noop (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) ...@@ -731,6 +727,15 @@ com_noop (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
731 } 727 }
732 728
733 static int 729 static int
730 com_check (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
731 {
732 int status = mu_imap_check (imap);
733 if (status)
734 report_failure ("check", status);
735 return 0;
736 }
737
738 static int
734 com_fetch (int argc, char **argv) 739 com_fetch (int argc, char **argv)
735 { 740 {
736 int status; 741 int status;
...@@ -739,7 +744,7 @@ com_fetch (int argc, char **argv) ...@@ -739,7 +744,7 @@ com_fetch (int argc, char **argv)
739 mu_imap_register_callback_function (imap, MU_IMAP_CB_FETCH, 744 mu_imap_register_callback_function (imap, MU_IMAP_CB_FETCH,
740 imap_fetch_callback, 745 imap_fetch_callback,
741 out); 746 out);
742 status = mu_imap_fetch (imap, argv[1], argv[2]); 747 status = mu_imap_fetch (imap, 0, argv[1], argv[2]);
743 mu_stream_destroy (&out); 748 mu_stream_destroy (&out);
744 mu_imap_register_callback_function (imap, MU_IMAP_CB_FETCH, 749 mu_imap_register_callback_function (imap, MU_IMAP_CB_FETCH,
745 imap_fetch_callback, 750 imap_fetch_callback,
...@@ -749,6 +754,60 @@ com_fetch (int argc, char **argv) ...@@ -749,6 +754,60 @@ com_fetch (int argc, char **argv)
749 return 0; 754 return 0;
750 } 755 }
751 756
757 static int
758 com_store (int argc, char **argv)
759 {
760 int status = mu_imap_store (imap, 0, argv[1], argv[2]);
761 if (status)
762 report_failure ("store", status);
763 return 0;
764 }
765
766 static int
767 com_close (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
768 {
769 int status = mu_imap_close (imap);
770 if (status)
771 report_failure ("close", status);
772 return 0;
773 }
774
775 static int
776 com_unselect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
777 {
778 int status = mu_imap_noop (imap);
779 if (status)
780 report_failure ("unselect", status);
781 return 0;
782 }
783
784 static int
785 com_delete (int argc, char **argv)
786 {
787 int status = mu_imap_delete (imap, argv[1]);
788 if (status)
789 report_failure ("delete", status);
790 return 0;
791 }
792
793 static int
794 com_rename (int argc, char **argv)
795 {
796 int status = mu_imap_rename (imap, argv[1], argv[2]);
797 if (status)
798 report_failure ("rename", status);
799 return 0;
800 }
801
802 static int
803 com_expunge (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
804 {
805 int status = mu_imap_expunge (imap);
806 if (status)
807 report_failure ("expunge", status);
808 return 0;
809 }
810
752 struct mutool_command imap_comtab[] = { 811 struct mutool_command imap_comtab[] = {
753 { "capability", 1, -1, 0, 812 { "capability", 1, -1, 0,
754 com_capability, 813 com_capability,
...@@ -761,7 +820,7 @@ struct mutool_command imap_comtab[] = { ...@@ -761,7 +820,7 @@ struct mutool_command imap_comtab[] = {
761 N_("control the protocol tracing") }, 820 N_("control the protocol tracing") },
762 { "connect", 1, 4, 0, 821 { "connect", 1, 4, 0,
763 com_connect, 822 com_connect,
764 /* TRANSLATORS: --tls is a keyword. */ 823 /* TRANSLATORS: -tls is a keyword. */
765 N_("[-tls] HOSTNAME [PORT]"), 824 N_("[-tls] HOSTNAME [PORT]"),
766 N_("open connection") }, 825 N_("open connection") },
767 { "disconnect", 1, 1, 0, 826 { "disconnect", 1, 1, 0,
...@@ -784,6 +843,10 @@ struct mutool_command imap_comtab[] = { ...@@ -784,6 +843,10 @@ struct mutool_command imap_comtab[] = {
784 com_noop, 843 com_noop,
785 NULL, 844 NULL,
786 N_("no operation (keepalive)") }, 845 N_("no operation (keepalive)") },
846 { "check", 1, 1, 0,
847 com_check,
848 NULL,
849 N_("request a server checkpoint") },
787 { "select", 1, 2, 0, 850 { "select", 1, 2, 0,
788 com_select, 851 com_select,
789 N_("[MBOX]"), 852 N_("[MBOX]"),
...@@ -800,6 +863,30 @@ struct mutool_command imap_comtab[] = { ...@@ -800,6 +863,30 @@ struct mutool_command imap_comtab[] = {
800 com_fetch, 863 com_fetch,
801 N_("MSGSET ITEMS"), 864 N_("MSGSET ITEMS"),
802 N_("fetch message data") }, 865 N_("fetch message data") },
866 { "store", 3, 3, CMD_COALESCE_EXTRA_ARGS,
867 com_store,
868 N_("MSGSET ITEMS"),
869 N_("alter mailbox data") },
870 { "close", 1, 1, 0,
871 com_close,
872 NULL,
873 N_("close the mailbox (with expunge)") },
874 { "unselect", 1, 1, 0,
875 com_unselect,
876 NULL,
877 N_("close the mailbox (without expunge)") },
878 { "delete", 2, 2, 0,
879 com_delete,
880 N_("MAILBOX"),
881 N_("delete the mailbox") },
882 { "rename", 3, 3, 0,
883 com_rename,
884 N_("OLD-NAME NEW-NAME"),
885 N_("rename existing mailbox") },
886 { "expunge", 1, 1, 0,
887 com_expunge,
888 NULL,
889 N_("permanently remove messages marked for deletion") },
803 { "quit", 1, 1, 0, 890 { "quit", 1, 1, 0,
804 com_logout, 891 com_logout,
805 NULL, 892 NULL,
......
...@@ -23,7 +23,7 @@ typedef int (*mutool_action_t) (int argc, char **argv); ...@@ -23,7 +23,7 @@ typedef int (*mutool_action_t) (int argc, char **argv);
23 struct mutool_command 23 struct mutool_command
24 { 24 {
25 const char *name; /* User printable name of the function. */ 25 const char *name; /* User printable name of the function. */
26 int argmin; /* Min. acceptable number of arguments (> 1) */ 26 int argmin; /* Min. acceptable number of arguments (>= 1) */
27 int argmax; /* Max. allowed number of arguments (-1 means not 27 int argmax; /* Max. allowed number of arguments (-1 means not
28 limited */ 28 limited */
29 int flags; 29 int flags;
......
...@@ -521,8 +521,9 @@ execute_line (char *line) ...@@ -521,8 +521,9 @@ execute_line (char *line)
521 int status = 0; 521 int status = 0;
522 522
523 ws.ws_comment = "#"; 523 ws.ws_comment = "#";
524 ws.ws_escape = "\\\"";
524 rc = mu_wordsplit (line, &ws, 525 rc = mu_wordsplit (line, &ws,
525 MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT| 526 MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT|MU_WRDSF_ESCAPE|
526 MU_WRDSF_INCREMENTAL|MU_WRDSF_APPEND); 527 MU_WRDSF_INCREMENTAL|MU_WRDSF_APPEND);
527 if (rc == MU_WRDSE_NOINPUT) 528 if (rc == MU_WRDSE_NOINPUT)
528 { 529 {
......