Commit 18aebf95 18aebf95ecc3c26b4e93075da9bb61a9fcf8bff7 by Jakob Kaivo

These files should be in the repository, too %-)

1 parent ae4073c4
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _IMAP4D_H
19 #define _IMAP4D_H 1
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <sys/wait.h>
31 #include <sys/types.h>
32 #include <syslog.h>
33 #include <pwd.h>
34 #include <grp.h>
35 #include <stdarg.h>
36 #include <sys/time.h>
37 #include <sys/stat.h>
38
39 #include <argp.h>
40
41 #include <mailutils/mailbox.h>
42 #include <mailutils/message.h>
43 #include <mailutils/header.h>
44 #include <mailutils/body.h>
45
46 #include <argcv.h>
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 #ifndef __P
53 # ifdef __STDC__
54 # define __P(args) args
55 # else
56 # define __P(args) ()
57 # endif
58 #endif /*__P */
59
60 /* Type definitions */
61 #ifndef Function
62 typedef int Function ();
63 #endif
64
65 struct imap4d_command {
66 char *name;
67 Function *func;
68 int states;
69 };
70
71 /* Global variables and constants*/
72 #define STATE_NONE 1<<0
73 #define STATE_NONAUTH 1<<1
74 #define STATE_AUTH 1<<2
75 #define STATE_SEL 1<<3
76 #define STATE_LOGOUT 1<<4
77
78 #define STATE_ALL (STATE_NONE | STATE_NONAUTH | STATE_AUTH | STATE_SEL \
79 | STATE_LOGOUT)
80
81 #define TAG_NONE 0
82 #define TAG_SEQ 1
83
84 #define RESP_OK 0
85 #define RESP_BAD 1
86 #define RESP_NO 2
87
88 extern const struct imap4d_command imap4d_command_table[];
89
90 /* Functions */
91 int imap4d_capability __P ((int argc, char **argv));
92 int imap4d_noop __P ((int argc, char **argv));
93 int imap4d_logout __P ((int argc, char **argv));
94 int imap4d_authenticate __P ((int argc, char **argv));
95 int imap4d_login __P ((int argc, char **argv));
96 int imap4d_select __P ((int argc, char **argv));
97 int imap4d_examine __P ((int argc, char **argv));
98 int imap4d_create __P ((int argc, char **argv));
99 int imap4d_delete __P ((int argc, char **argv));
100 int imap4d_rename __P ((int argc, char **argv));
101 int imap4d_subscribe __P ((int argc, char **argv));
102 int imap4d_unsubscribe __P ((int argc, char **argv));
103 int imap4d_list __P ((int argc, char **argv));
104 int imap4d_lsub __P ((int argc, char **argv));
105 int imap4d_status __P ((int argc, char **argv));
106 int imap4d_append __P ((int argc, char **argv));
107 int imap4d_check __P ((int argc, char **argv));
108 int imap4d_close __P ((int argc, char **argv));
109 int imap4d_expunge __P ((int argc, char **argv));
110 int imap4d_search __P ((int argc, char **argv));
111 int imap4d_fetch __P ((int argc, char **argv));
112 int imap4d_store __P ((int argc, char **argv));
113 int imap4d_copy __P ((int argc, char **argv));
114 int imap4d_uid __P ((int argc, char **argv));
115
116 int util_out __P ((char *seq, int tag, char *f, ...));
117 int util_start __P ((char *seq));
118 int util_finish __P ((int argc, char **argv, int resp, char *f, ...));
119 int util_getstate __P((void));
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif /* _IMAP4D_H */
126
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "imap4d.h"
19
20 /*
21 *
22 */
23
24 int
25 imap4d_login (int argc, char **argv)
26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]);
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented");
29 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "imap4d.h"
19
20 /*
21 *
22 */
23
24 int
25 imap4d_logout (int argc, char **argv)
26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]);
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented");
29 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "imap4d.h"
19
20 /*
21 *
22 */
23
24 int
25 imap4d_noop (int argc, char **argv)
26 {
27 if (argc > 2)
28 return util_finish (argc, argv, RESP_BAD, "Too many arguments");
29 return util_finish (argc, argv, RESP_OK, "Completed");
30 }
1 /* argcv.c - simple functions for parsing input based on whitespace
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "argcv.h"
19
20 /*
21 * takes a string and splits it into several strings, breaking at ' '
22 * command is the string to split
23 * the number of strings is placed into argc
24 * the split strings are put into argv
25 * returns 0 on success, nonzero on failure
26 */
27
28 int
29 argcv_get (const char *command, int *argc, char ***argv)
30 {
31 int len = strlen (command);
32 int i = 0, j = 0;
33 int start = 0;
34
35 if (len < 1)
36 return 1;
37
38 *argc = 1;
39
40 for (i = 0; i < len; i++)
41 if (command[i] == ' ')
42 (*argc)++;
43
44 *argv = malloc ((*argc + 1) * sizeof (char *));
45
46 for (i = 0; i <= len; i++)
47 {
48 if (command[i] == ' ' || command[i] == '\0')
49 {
50 (*argv)[j] = malloc ((i-start) * sizeof (char));
51 if (argv[j] == NULL && (i-start > 0))
52 return 1;
53 strncpy ((*argv)[j], &command[start], i-start);
54 (*argv)[j][i-start] = '\0';
55 j++;
56 start = i+1;
57 }
58 }
59 return 0;
60 }
61
62 /*
63 * frees all elements of an argv array
64 * argc is the number of elements
65 * argv is the array
66 */
67 int
68 argcv_free (int argc, char **argv)
69 {
70 while (--argc >= 0)
71 free (argv[argc]);
72 free (argv);
73 return 1;
74 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program 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 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _ARGCV_H
19 #define _ARGCV_H 1
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #ifndef __P
31 # ifdef __STDC__
32 # define __P(args) args
33 # else
34 # define __P(args) ()
35 # endif
36 #endif /*__P */
37
38 int argcv_get __P((const char *command, int *argc, char ***argv));
39 int argcv_free __P((int argc, char **argv));
40
41 #ifdef __cplusplus
42 }
43 #endif
44
45 #endif /* _ARGCV_H */
46