Codebase list fdm / c0c450e
Mass renaming round 1. Move some stuff into new header files. Nicholas Marriott 17 years ago
37 changed file(s) with 830 addition(s) and 647 deletion(s). Raw diff Collapse all Expand all
2828 #include <unistd.h>
2929
3030 #include "fdm.h"
31 #include "deliver.h"
32 #include "fetch.h"
33 #include "match.h"
3134
3235 int poll_account(struct io *, struct account *);
3336 int fetch_account(struct io *, struct account *, double);
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "deliver.h"
2324
24 int add_header_deliver(struct deliver_ctx *, struct action *);
25 void add_header_desc(struct action *, char *, size_t);
25 int deliver_add_header_deliver(struct deliver_ctx *, struct action *);
26 void deliver_add_header_desc(struct action *, char *, size_t);
2627
27 struct deliver deliver_add_header = { DELIVER_INCHILD,
28 add_header_deliver,
29 add_header_desc };
28 struct deliver deliver_add_header = {
29 DELIVER_INCHILD,
30 deliver_add_header_deliver,
31 deliver_add_header_desc
32 };
3033
3134 int
32 add_header_deliver(struct deliver_ctx *dctx, struct action *t)
35 deliver_add_header_deliver(struct deliver_ctx *dctx, struct action *t)
3336 {
3437 struct account *a = dctx->account;
3538 struct mail *m = dctx->mail;
6164 }
6265
6366 void
64 add_header_desc(struct action *t, char *buf, size_t len)
67 deliver_add_header_desc(struct action *t, char *buf, size_t len)
6568 {
6669 struct add_header_data *data = t->data;
6770
2121 #include <vis.h>
2222
2323 #include "fdm.h"
24 #include "deliver.h"
2425
25 int append_string_deliver(struct deliver_ctx *, struct action *);
26 void append_string_desc(struct action *, char *, size_t);
26 int deliver_append_string_deliver(struct deliver_ctx *, struct action *);
27 void deliver_append_string_desc(struct action *, char *, size_t);
2728
28 struct deliver deliver_append_string = { DELIVER_INCHILD,
29 append_string_deliver,
30 append_string_desc };
29 struct deliver deliver_append_string = {
30 DELIVER_INCHILD,
31 deliver_append_string_deliver,
32 deliver_append_string_desc
33 };
3134
3235 int
33 append_string_deliver(struct deliver_ctx *dctx, struct action *t)
36 deliver_append_string_deliver(struct deliver_ctx *dctx, struct action *t)
3437 {
3538 struct mail *m = dctx->mail;
3639 char *ptr = t->data;
4548 }
4649
4750 void
48 append_string_desc(struct action *t, char *buf, size_t len)
51 deliver_append_string_desc(struct action *t, char *buf, size_t len)
4952 {
5053 size_t sz;
5154
2424 #include <unistd.h>
2525
2626 #include "fdm.h"
27 #include "deliver.h"
2728
28 int append_deliver(struct deliver_ctx *, struct action *);
29 void append_desc(struct action *, char *, size_t);
29 int deliver_append_deliver(struct deliver_ctx *, struct action *);
30 void deliver_append_desc(struct action *, char *, size_t);
3031
31 struct deliver deliver_append = { DELIVER_ASUSER, append_deliver, append_desc };
32 struct deliver deliver_append = {
33 DELIVER_ASUSER,
34 deliver_append_deliver,
35 deliver_append_desc
36 };
3237
3338 int
34 append_deliver(struct deliver_ctx *dctx, struct action *t)
39 deliver_append_deliver(struct deliver_ctx *dctx, struct action *t)
3540 {
3641 return (do_write(dctx, t, 1));
3742 }
3843
3944 void
40 append_desc(struct action *t, char *buf, size_t len)
45 deliver_append_desc(struct action *t, char *buf, size_t len)
4146 {
4247 xsnprintf(buf, len, "append \"%s\"", (char *) t->data);
4348 }
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "deliver.h"
2324
24 int drop_deliver(struct deliver_ctx *, struct action *);
25 void drop_desc(struct action *, char *, size_t);
25 int deliver_drop_deliver(struct deliver_ctx *, struct action *);
26 void deliver_drop_desc(struct action *, char *, size_t);
2627
27 struct deliver deliver_drop = { DELIVER_INCHILD, drop_deliver, drop_desc };
28 struct deliver deliver_drop = {
29 DELIVER_INCHILD,
30 deliver_drop_deliver,
31 deliver_drop_desc
32 };
2833
2934 int
30 drop_deliver(struct deliver_ctx *dctx, unused struct action *t)
35 deliver_drop_deliver(struct deliver_ctx *dctx, unused struct action *t)
3136 {
3237 *dctx->decision = DECISION_DROP;
3338
3540 }
3641
3742 void
38 drop_desc(unused struct action *t, char *buf, size_t len)
43 deliver_drop_desc(unused struct action *t, char *buf, size_t len)
3944 {
4045 strlcpy(buf, "drop", len);
4146 }
2424 #include <unistd.h>
2525
2626 #include "fdm.h"
27 #include "deliver.h"
2728
28 int exec_deliver(struct deliver_ctx *, struct action *);
29 void exec_desc(struct action *, char *, size_t);
29 int deliver_exec_deliver(struct deliver_ctx *, struct action *);
30 void deliver_exec_desc(struct action *, char *, size_t);
3031
31 struct deliver deliver_exec = { DELIVER_ASUSER, exec_deliver, exec_desc };
32 struct deliver deliver_exec = {
33 DELIVER_ASUSER,
34 deliver_exec_deliver,
35 deliver_exec_desc
36 };
3237
3338 int
34 exec_deliver(struct deliver_ctx *dctx, struct action *t)
39 deliver_exec_deliver(struct deliver_ctx *dctx, struct action *t)
3540 {
3641 return (do_pipe(dctx, t, 0));
3742 }
3843
3944 void
40 exec_desc(struct action *t, char *buf, size_t len)
45 deliver_exec_desc(struct action *t, char *buf, size_t len)
4146 {
4247 xsnprintf(buf, len, "exec \"%s\"", (char *) t->data);
4348 }
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "deliver.h"
2324
24 int keep_deliver(struct deliver_ctx *, struct action *);
25 void keep_desc(struct action *, char *, size_t);
25 int deliver_keep_deliver(struct deliver_ctx *, struct action *);
26 void deliver_keep_desc(struct action *, char *, size_t);
2627
27 struct deliver deliver_keep = { DELIVER_INCHILD, keep_deliver, keep_desc };
28 struct deliver deliver_keep = {
29 DELIVER_INCHILD,
30 deliver_keep_deliver,
31 deliver_keep_desc
32 };
2833
2934 int
30 keep_deliver(struct deliver_ctx *dctx, unused struct action *t)
35 deliver_keep_deliver(struct deliver_ctx *dctx, unused struct action *t)
3136 {
3237 *dctx->decision = DECISION_KEEP;
3338
3540 }
3641
3742 void
38 keep_desc(unused struct action *t, char *buf, size_t len)
43 deliver_keep_desc(unused struct action *t, char *buf, size_t len)
3944 {
4045 strlcpy(buf, "keep", len);
4146 }
2727 #include <unistd.h>
2828
2929 #include "fdm.h"
30
31 int maildir_deliver(struct deliver_ctx *, struct action *);
32 void maildir_desc(struct action *, char *, size_t);
33
34 struct deliver deliver_maildir = { DELIVER_ASUSER, maildir_deliver,
35 maildir_desc };
30 #include "deliver.h"
31
32 int deliver_maildir_deliver(struct deliver_ctx *, struct action *);
33 void deliver_maildir_desc(struct action *, char *, size_t);
34
35 struct deliver deliver_maildir = {
36 DELIVER_ASUSER,
37 deliver_maildir_deliver,
38 deliver_maildir_desc
39 };
3640
3741 int
38 maildir_deliver(struct deliver_ctx *dctx, struct action *t)
42 deliver_maildir_deliver(struct deliver_ctx *dctx, struct action *t)
3943 {
4044 struct account *a = dctx->account;
4145 struct mail *m = dctx->mail;
228232 }
229233
230234 void
231 maildir_desc(struct action *t, char *buf, size_t len)
235 deliver_maildir_desc(struct action *t, char *buf, size_t len)
232236 {
233237 xsnprintf(buf, len, "maildir \"%s\"", (char *) t->data);
234238 }
2727 #include <unistd.h>
2828
2929 #include "fdm.h"
30 #include "deliver.h"
3031
3132 /* With gcc 2.95.x, you can't include zlib.h before openssl.h. */
3233 #include <zlib.h>
3334
34 int mbox_deliver(struct deliver_ctx *, struct action *);
35 void mbox_desc(struct action *, char *, size_t);
35 int deliver_mbox_deliver(struct deliver_ctx *, struct action *);
36 void deliver_mbox_desc(struct action *, char *, size_t);
3637
3738 int mbox_write(int, gzFile, const void *, size_t);
3839
39 struct deliver deliver_mbox = { DELIVER_ASUSER, mbox_deliver, mbox_desc };
40 struct deliver deliver_mbox = {
41 DELIVER_ASUSER,
42 deliver_mbox_deliver,
43 deliver_mbox_desc
44 };
4045
4146 int
4247 mbox_write(int fd, gzFile gzf, const void *buf, size_t len)
5964 }
6065
6166 int
62 mbox_deliver(struct deliver_ctx *dctx, struct action *t)
67 deliver_mbox_deliver(struct deliver_ctx *dctx, struct action *t)
6368 {
6469 struct account *a = dctx->account;
6570 struct mail *m = dctx->mail;
193198 }
194199
195200 void
196 mbox_desc(struct action *t, char *buf, size_t len)
201 deliver_mbox_desc(struct action *t, char *buf, size_t len)
197202 {
198203 struct mbox_data *data = t->data;
199204
2424 #include <unistd.h>
2525
2626 #include "fdm.h"
27 #include "deliver.h"
2728
28 int pipe_deliver(struct deliver_ctx *, struct action *);
29 void pipe_desc(struct action *, char *, size_t);
29 int deliver_pipe_deliver(struct deliver_ctx *, struct action *);
30 void deliver_pipe_desc(struct action *, char *, size_t);
3031
31 struct deliver deliver_pipe = { DELIVER_ASUSER, pipe_deliver, pipe_desc };
32 struct deliver deliver_pipe = {
33 DELIVER_ASUSER,
34 deliver_pipe_deliver,
35 deliver_pipe_desc
36 };
3237
3338 int
34 pipe_deliver(struct deliver_ctx *dctx, struct action *t)
39 deliver_pipe_deliver(struct deliver_ctx *dctx, struct action *t)
3540 {
3641 return (do_pipe(dctx, t, 1));
3742 }
3843
3944 void
40 pipe_desc(struct action *t, char *buf, size_t len)
45 deliver_pipe_desc(struct action *t, char *buf, size_t len)
4146 {
4247 xsnprintf(buf, len, "pipe \"%s\"", (char *) t->data);
4348 }
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "deliver.h"
2324
24 int remove_header_deliver(struct deliver_ctx *, struct action *);
25 void remove_header_desc(struct action *, char *, size_t);
25 int deliver_remove_header_deliver(struct deliver_ctx *, struct action *);
26 void deliver_remove_header_desc(struct action *, char *, size_t);
2627
27 struct deliver deliver_remove_header = { DELIVER_INCHILD,
28 remove_header_deliver,
29 remove_header_desc };
28 struct deliver deliver_remove_header = {
29 DELIVER_INCHILD,
30 deliver_remove_header_deliver,
31 deliver_remove_header_desc
32 };
3033
3134 int
32 remove_header_deliver(struct deliver_ctx *dctx, struct action *t)
35 deliver_remove_header_deliver(struct deliver_ctx *dctx, struct action *t)
3336 {
3437 struct mail *m = dctx->mail;
3538 char *ptr;
7780 }
7881
7982 void
80 remove_header_desc(struct action *t, char *buf, size_t len)
83 deliver_remove_header_desc(struct action *t, char *buf, size_t len)
8184 {
8285 xsnprintf(buf, len, "remove-header \"%s\"", (char *) t->data);
8386 }
2626 #include <unistd.h>
2727
2828 #include "fdm.h"
29 #include "deliver.h"
2930
30 int rewrite_deliver(struct deliver_ctx *, struct action *);
31 void rewrite_desc(struct action *, char *, size_t);
31 int deliver_rewrite_deliver(struct deliver_ctx *, struct action *);
32 void deliver_rewrite_desc(struct action *, char *, size_t);
3233
33 struct deliver deliver_rewrite = { DELIVER_WRBACK, rewrite_deliver,
34 rewrite_desc };
34 struct deliver deliver_rewrite = {
35 DELIVER_WRBACK,
36 deliver_rewrite_deliver,
37 deliver_rewrite_desc
38 };
3539
3640 int
37 rewrite_deliver(struct deliver_ctx *dctx, struct action *t)
41 deliver_rewrite_deliver(struct deliver_ctx *dctx, struct action *t)
3842 {
3943 struct account *a = dctx->account;
4044 struct mail *m = dctx->mail;
124128 }
125129
126130 void
127 rewrite_desc(struct action *t, char *buf, size_t len)
131 deliver_rewrite_desc(struct action *t, char *buf, size_t len)
128132 {
129133 xsnprintf(buf, len, "rewrite \"%s\"", (char *) t->data);
130134 }
2525 #include <unistd.h>
2626
2727 #include "fdm.h"
28
29 int smtp_deliver(struct deliver_ctx *, struct action *);
30 void smtp_desc(struct action *, char *, size_t);
28 #include "deliver.h"
29
30 int deliver_smtp_deliver(struct deliver_ctx *, struct action *);
31 void deliver_smtp_desc(struct action *, char *, size_t);
3132
3233 int smtp_code(char *);
3334
34 struct deliver deliver_smtp = { DELIVER_ASUSER, smtp_deliver, smtp_desc };
35 struct deliver deliver_smtp = {
36 DELIVER_ASUSER,
37 deliver_smtp_deliver,
38 deliver_smtp_desc
39 };
3540
3641 int
3742 smtp_code(char *line)
5661 }
5762
5863 int
59 smtp_deliver(struct deliver_ctx *dctx, struct action *t)
64 deliver_smtp_deliver(struct deliver_ctx *dctx, struct action *t)
6065 {
6166 struct account *a = dctx->account;
6267 struct mail *m = dctx->mail;
189194 }
190195
191196 void
192 smtp_desc(struct action *t, char *buf, size_t len)
197 deliver_smtp_desc(struct action *t, char *buf, size_t len)
193198 {
194199 struct smtp_data *data = t->data;
195200
2121 #include <string.h>
2222
2323 #include "fdm.h"
24 #include "deliver.h"
2425
25 int stdout_deliver(struct deliver_ctx *, struct action *);
26 void stdout_desc(struct action *, char *, size_t);
26 int deliver_stdout_deliver(struct deliver_ctx *, struct action *);
27 void deliver_stdout_desc(struct action *, char *, size_t);
2728
28 struct deliver deliver_stdout = { DELIVER_INCHILD,
29 stdout_deliver,
30 stdout_desc };
29 struct deliver deliver_stdout = {
30 DELIVER_INCHILD,
31 deliver_stdout_deliver,
32 deliver_stdout_desc
33 };
3134
3235 int
33 stdout_deliver(struct deliver_ctx *dctx, struct action *t)
36 deliver_stdout_deliver(struct deliver_ctx *dctx, struct action *t)
3437 {
3538 struct account *a = dctx->account;
3639 struct mail *m = dctx->mail;
6366 }
6467
6568 void
66 stdout_desc(struct action *t, char *buf, size_t len)
69 deliver_stdout_desc(struct action *t, char *buf, size_t len)
6770 {
6871 struct stdout_data *data = t->data;
6972
2424 #include <unistd.h>
2525
2626 #include "fdm.h"
27 #include "deliver.h"
2728
28 int write_deliver(struct deliver_ctx *, struct action *);
29 void write_desc(struct action *, char *, size_t);
29 int deliver_write_deliver(struct deliver_ctx *, struct action *);
30 void deliver_write_desc(struct action *, char *, size_t);
3031
31 struct deliver deliver_write = { DELIVER_ASUSER, write_deliver, write_desc };
32 struct deliver deliver_write = {
33 DELIVER_ASUSER,
34 deliver_write_deliver,
35 deliver_write_desc
36 };
3237
3338 int
34 write_deliver(struct deliver_ctx *dctx, struct action *t)
39 deliver_write_deliver(struct deliver_ctx *dctx, struct action *t)
3540 {
3641 return (do_write(dctx, t, 0));
3742 }
3843
3944 void
40 write_desc(struct action *t, char *buf, size_t len)
45 deliver_write_desc(struct action *t, char *buf, size_t len)
4146 {
4247 xsnprintf(buf, len, "write \"%s\"", (char *) t->data);
4348 }
0 /* $Id$ */
1
2 /*
3 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
14 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
15 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #ifndef DELIVER_H
19 #define DELIVER_H
20
21 /* Deliver return codes. */
22 #define DELIVER_SUCCESS 0
23 #define DELIVER_FAILURE 1
24
25 /* Deliver context. */
26 struct deliver_ctx {
27 struct account *account;
28 struct mail *mail;
29
30 struct mail wr_mail;
31
32 enum decision *decision;
33
34 int *pm_valid;
35 regmatch_t pm[NPMATCH];
36 };
37
38 /* Delivery types. */
39 enum delivertype {
40 DELIVER_INCHILD, /* do not pass up to parent */
41 DELIVER_ASUSER, /* do pass up to parent to drop privs */
42 DELIVER_WRBACK /* modifies mail: pass up to parent and expect
43 a new mail back */
44 };
45
46 /* Deliver functions. */
47 struct deliver {
48 enum delivertype type;
49
50 int (*deliver)(struct deliver_ctx *, struct action *);
51 void (*desc)(struct action *, char *, size_t);
52 };
53
54 /* Deliver smtp states. */
55 enum smtp_state {
56 SMTP_CONNECTING,
57 SMTP_HELO,
58 SMTP_FROM,
59 SMTP_TO,
60 SMTP_DATA,
61 SMTP_DONE,
62 SMTP_QUIT
63 };
64
65 /* Deliver smtp data. */
66 struct smtp_data {
67 struct server server;
68 char *to;
69 };
70
71 /* Deliver mbox data. */
72 struct mbox_data {
73 char *path;
74 int compress;
75 };
76
77 /* Deliver stdout data. */
78 struct stdout_data {
79 int add_from;
80 };
81
82 /* Deliver add-header data. */
83 struct add_header_data {
84 char *hdr;
85 char *value;
86 };
87
88 /* deliver-smtp.c */
89 extern struct deliver deliver_smtp;
90
91 /* deliver-smtp.c */
92 extern struct deliver deliver_stdout;
93
94 /* deliver-pipe.c */
95 extern struct deliver deliver_pipe;
96 int do_pipe(struct deliver_ctx *, struct action *, int);
97
98 /* deliver-exec.c */
99 extern struct deliver deliver_exec;
100
101 /* deliver-drop.c */
102 extern struct deliver deliver_drop;
103
104 /* deliver-keep.c */
105 extern struct deliver deliver_keep;
106
107 /* deliver-maildir.c */
108 extern struct deliver deliver_maildir;
109
110 /* deliver-remove-header.c */
111 extern struct deliver deliver_remove_header;
112
113 /* deliver-add-header.c */
114 extern struct deliver deliver_add_header;
115
116 /* deliver-append-string.c */
117 extern struct deliver deliver_append_string;
118
119 /* deliver-mbox.c */
120 extern struct deliver deliver_mbox;
121
122 /* deliver-write.c */
123 extern struct deliver deliver_write;
124 int do_write(struct deliver_ctx *, struct action *, int);
125
126 /* deliver-append.c */
127 extern struct deliver deliver_append;
128
129 /* deliver-rewrite.c */
130 extern struct deliver deliver_rewrite;
131
132 #endif
+0
-373
fdm.h less more
589589 struct io *io_err;
590590 };
591591
592 /* Poll return codes. */
593 #define POLL_SUCCESS FETCH_SUCCESS
594 #define POLL_ERROR FETCH_ERROR
595
596 /* Fetch return codes. */
597 #define FETCH_SUCCESS 0
598 #define FETCH_ERROR 1
599 #define FETCH_OVERSIZE 2
600 #define FETCH_COMPLETE 3
601
602 /* Fetch functions. */
603 struct fetch {
604 const char *ports[2]; /* normal port, ssl port */
605
606 int (*init)(struct account *);
607 int (*connect)(struct account *);
608 int (*poll)(struct account *, u_int *);
609 int (*fetch)(struct account *, struct mail *);
610 int (*purge)(struct account *);
611 int (*delete)(struct account *);
612 int (*keep)(struct account *);
613 int (*disconnect)(struct account *);
614 int (*free)(struct account *);
615 void (*desc)(struct account *, char *, size_t);
616 };
617
618 /* Deliver context. */
619 struct deliver_ctx {
620 struct account *account;
621 struct mail *mail;
622
623 struct mail wr_mail;
624
625 enum decision *decision;
626
627 int *pm_valid;
628 regmatch_t pm[NPMATCH];
629 };
630
631 /* Deliver return codes. */
632 #define DELIVER_SUCCESS 0
633 #define DELIVER_FAILURE 1
634
635 /* Delivery types. */
636 enum delivertype {
637 DELIVER_INCHILD, /* do not pass up to parent */
638 DELIVER_ASUSER, /* do pass up to parent to drop privs */
639 DELIVER_WRBACK /* modifies mail: pass up to parent and expect
640 a new mail back */
641 };
642
643 /* Deliver functions. */
644 struct deliver {
645 enum delivertype type;
646
647 int (*deliver)(struct deliver_ctx *, struct action *);
648 void (*desc)(struct action *, char *, size_t);
649 };
650
651 #define MATCH_FALSE 0
652 #define MATCH_TRUE 1
653 #define MATCH_ERROR 2
654
655 /* Match context. */
656 struct match_ctx {
657 struct io *io;
658 struct account *account;
659 struct mail *mail;
660
661 enum decision decision;
662
663 int matched;
664 int stopped;
665
666 int pm_valid;
667 regmatch_t pm[NPMATCH];
668 };
669
670 /* Match functions. */
671 struct match {
672 int (*match)(struct match_ctx *, struct expritem *);
673 void (*desc)(struct expritem *, char *, size_t);
674 };
675
676592 /* Privsep message types. */
677593 enum msgtype {
678594 MSG_ACTION,
714630 CMP_LT,
715631 CMP_GT
716632 };
717
718 /* Match attachment data. */
719 struct attachment_data {
720 enum {
721 ATTACHOP_COUNT,
722 ATTACHOP_TOTALSIZE,
723 ATTACHOP_ANYSIZE,
724 ATTACHOP_ANYTYPE,
725 ATTACHOP_ANYNAME
726 } op;
727
728 enum cmp cmp;
729 union {
730 size_t size;
731 long long num;
732 char *str;
733 struct re re;
734 } value;
735 };
736
737 /* Match age data. */
738 struct age_data {
739 long long time;
740 enum cmp cmp;
741 };
742
743 /* Match size data. */
744 struct size_data {
745 size_t size;
746 enum cmp cmp;
747 };
748
749 /* Match tagged data. */
750 struct tagged_data {
751 char *tag;
752 };
753
754 /* Match string data. */
755 struct string_data {
756 struct re re;
757
758 char *str;
759 };
760
761 /* Match regexp data. */
762 struct regexp_data {
763 struct re re;
764
765 enum area area;
766 };
767
768 /* Match command data. */
769 struct command_data {
770 char *cmd;
771 uid_t uid;
772 int pipe; /* pipe mail to command */
773
774 struct re re; /* re->re NULL to not check */
775 int ret; /* -1 to not check */
776 };
777
778 /* Fetch maildir data. */
779 struct maildir_data {
780 struct strings *maildirs;
781
782 struct strings *paths;
783 u_int index;
784
785 DIR *dirp;
786 char *path;
787 char entry[MAXPATHLEN];
788 char maildir[MAXPATHLEN];
789 };
790
791 /* NNTP group entry. */
792 struct nntp_group {
793 char *name;
794 int ignore;
795
796 u_int size;
797 u_int last;
798 char *id;
799 };
800
801 /* NNTP group list. */
802 ARRAY_DECL(nntp_groups, struct nntp_group *);
803
804 /* Fetch nntp data. */
805 struct nntp_data {
806 char *path;
807
808 struct server server;
809 struct strings *names;
810
811 u_int group;
812 struct nntp_groups groups;
813
814 struct io *io;
815 };
816 #define GET_GROUP(d, i) ARRAY_ITEM(&d->groups, i, struct nntp_group *)
817 #define CURRENT_GROUP(d) GET_GROUP(d, d->group)
818 #define TOTAL_GROUPS(d) ARRAY_LENGTH(&d->groups)
819 #define ADD_GROUP(d, g) ARRAY_ADD(&d->groups, g, struct nntp_group *)
820
821 /* Fetch stdin data. */
822 struct stdin_data {
823 int complete;
824
825 struct io *io;
826 };
827
828 /* Fetch pop3 data. */
829 struct pop3_data {
830 char *user;
831 char *pass;
832
833 struct server server;
834
835 u_int cur;
836 u_int num;
837
838 char *uid;
839 struct strings kept;
840
841 struct io *io;
842 };
843
844 /* IMAP tag types. */
845 #define IMAP_TAG_NONE -1
846 #define IMAP_TAG_CONTINUE -2
847 #define IMAP_TAG_ERROR -3
848
849 /* IMAP line types. */
850 #define IMAP_TAGGED 0
851 #define IMAP_CONTINUE 1
852 #define IMAP_UNTAGGED 2
853 #define IMAP_RAW 3
854
855 /* Fetch imap data. */
856 struct imap_data {
857 struct server server;
858 char *pipecmd;
859
860 struct io *io;
861 struct cmd *cmd;
862
863 char *user;
864 char *pass;
865 char *folder;
866
867 int tag;
868 u_int cur;
869 u_int num;
870
871 u_int uid;
872 ARRAY_DECL(, u_int) kept;
873
874 char *src;
875
876 size_t llen;
877 char *lbuf;
878
879 char *(*getln)(struct account *a, int);
880 int (*putln)(struct account *a, const char *, ...);
881 void (*flush)(struct account *a);
882 };
883
884 /* Deliver smtp states. */
885 enum smtp_state {
886 SMTP_CONNECTING,
887 SMTP_HELO,
888 SMTP_FROM,
889 SMTP_TO,
890 SMTP_DATA,
891 SMTP_DONE,
892 SMTP_QUIT
893 };
894
895 /* Deliver smtp data. */
896 struct smtp_data {
897 struct server server;
898 char *to;
899 };
900
901 /* Deliver mbox data. */
902 struct mbox_data {
903 char *path;
904 int compress;
905 };
906
907 /* Deliver stdout data. */
908 struct stdout_data {
909 int add_from;
910 };
911
912 /* Deliver add-header data. */
913 struct add_header_data {
914 char *hdr;
915 char *value;
916 };
917
918 /* match-age.c */
919 extern struct match match_age;
920
921 /* match-attachment.c */
922 extern struct match match_attachment;
923
924 /* match-matched.c */
925 extern struct match match_matched;
926
927 /* match-unmatched.c */
928 extern struct match match_unmatched;
929
930 /* match-size.c */
931 extern struct match match_size;
932
933 /* match-tagged.c */
934 extern struct match match_tagged;
935
936 /* match-string.c */
937 extern struct match match_string;
938
939 /* match-command.c */
940 extern struct match match_command;
941
942 /* match-regexp.c */
943 extern struct match match_regexp;
944
945 /* fetch-maildir.c */
946 extern struct fetch fetch_maildir;
947
948 /* fetch-stdin.c */
949 extern struct fetch fetch_stdin;
950
951 /* fetch-nntp.c */
952 extern struct fetch fetch_nntp;
953
954 /* fetch-pop3.c */
955 extern struct fetch fetch_pop3;
956
957 /* fetch-imap.c */
958 extern struct fetch fetch_imap;
959
960 /* fetch-imappipe.c */
961 extern struct fetch fetch_imappipe;
962
963 /* deliver-smtp.c */
964 extern struct deliver deliver_smtp;
965
966 /* deliver-smtp.c */
967 extern struct deliver deliver_stdout;
968
969 /* deliver-pipe.c */
970 extern struct deliver deliver_pipe;
971 int do_pipe(struct deliver_ctx *, struct action *, int);
972
973 /* deliver-exec.c */
974 extern struct deliver deliver_exec;
975
976 /* deliver-drop.c */
977 extern struct deliver deliver_drop;
978
979 /* deliver-keep.c */
980 extern struct deliver deliver_keep;
981
982 /* deliver-maildir.c */
983 extern struct deliver deliver_maildir;
984
985 /* deliver-remove-header.c */
986 extern struct deliver deliver_remove_header;
987
988 /* deliver-add-header.c */
989 extern struct deliver deliver_add_header;
990
991 /* deliver-append-string.c */
992 extern struct deliver deliver_append_string;
993
994 /* deliver-mbox.c */
995 extern struct deliver deliver_mbox;
996
997 /* deliver-write.c */
998 extern struct deliver deliver_write;
999 int do_write(struct deliver_ctx *, struct action *, int);
1000
1001 /* deliver-append.c */
1002 extern struct deliver deliver_append;
1003
1004 /* deliver-rewrite.c */
1005 extern struct deliver deliver_rewrite;
1006633
1007634 #ifdef NO_SETRESUID
1008635 #define setresuid(r, e, s) setreuid(r, e)
2020 #include <unistd.h>
2121
2222 #include "fdm.h"
23 #include "fetch.h"
2324
24 int imap_connect(struct account *);
25 int imap_disconnect(struct account *);
26 void imap_desc(struct account *, char *, size_t);
25 int fetch_imap_connect(struct account *);
26 int fetch_imap_disconnect(struct account *);
27 void fetch_imap_desc(struct account *, char *, size_t);
2728
2829 int printflike2 imap_putln(struct account *, const char *, ...);
2930 char *imap_getln(struct account *, int);
3031 void imap_flush(struct account *);
3132
32 struct fetch fetch_imap = { { "imap", "imaps" },
33 imap_init, /* from imap-common.c */
34 imap_connect,
35 imap_poll, /* from imap-common.c */
36 imap_fetch, /* from imap-common.c */
37 imap_purge, /* from imap-common.c */
38 imap_delete, /* from imap-common.c */
39 imap_keep, /* from imap-common.c */
40 imap_disconnect,
41 imap_free, /* from imap-common.c */
42 imap_desc
33 struct fetch fetch_imap = {
34 { "imap", "imaps" },
35 imap_init, /* from imap-common.c */
36 fetch_imap_connect,
37 imap_poll, /* from imap-common.c */
38 imap_fetch, /* from imap-common.c */
39 imap_purge, /* from imap-common.c */
40 imap_delete, /* from imap-common.c */
41 imap_keep, /* from imap-common.c */
42 fetch_imap_disconnect,
43 imap_free, /* from imap-common.c */
44 fetch_imap_desc
4345 };
4446
4547 int printflike2
116118 }
117119
118120 int
119 imap_connect(struct account *a)
121 fetch_imap_connect(struct account *a)
120122 {
121123 struct imap_data *data = a->data;
122124 char *cause;
148150 }
149151
150152 int
151 imap_disconnect(struct account *a)
153 fetch_imap_disconnect(struct account *a)
152154 {
153155 struct imap_data *data = a->data;
154156
172174 }
173175
174176 void
175 imap_desc(struct account *a, char *buf, size_t len)
177 fetch_imap_desc(struct account *a, char *buf, size_t len)
176178 {
177179 struct imap_data *data = a->data;
178180
2020 #include <unistd.h>
2121
2222 #include "fdm.h"
23 #include "fetch.h"
2324
24 int imappipe_connect(struct account *);
25 int imappipe_disconnect(struct account *);
26 void imappipe_desc(struct account *, char *, size_t);
25 int fetch_imappipe_connect(struct account *);
26 int fetch_imappipe_disconnect(struct account *);
27 void fetch_imappipe_desc(struct account *, char *, size_t);
2728
2829 int printflike2 imappipe_putln(struct account *, const char *, ...);
2930 char *imappipe_getln(struct account *, int);
3031 void imappipe_flush(struct account *);
3132
32 struct fetch fetch_imappipe = { { NULL, NULL },
33 imap_init, /* from imap-common.c */
34 imappipe_connect,
35 imap_poll, /* from imap-common.c */
36 imap_fetch, /* from imap-common.c */
37 imap_purge, /* from imap-common.c */
38 imap_delete, /* from imap-common.c */
39 imap_keep, /* from imap-common.c */
40 imappipe_disconnect,
41 imap_free, /* from imap-common.c */
42 imappipe_desc,
33 struct fetch fetch_imappipe = {
34 { NULL, NULL },
35 imap_init, /* from imap-common.c */
36 fetch_imappipe_connect,
37 imap_poll, /* from imap-common.c */
38 imap_fetch, /* from imap-common.c */
39 imap_purge, /* from imap-common.c */
40 imap_delete, /* from imap-common.c */
41 imap_keep, /* from imap-common.c */
42 fetch_imappipe_disconnect,
43 imap_free, /* from imap-common.c */
44 fetch_imappipe_desc,
4345 };
4446
4547 int printflike2
123125 }
124126
125127 int
126 imappipe_connect(struct account *a)
128 fetch_imappipe_connect(struct account *a)
127129 {
128130 struct imap_data *data = a->data;
129131 char *cause;
156158 }
157159
158160 int
159 imappipe_disconnect(struct account *a)
161 fetch_imappipe_disconnect(struct account *a)
160162 {
161163 struct imap_data *data = a->data;
162164
178180 }
179181
180182 void
181 imappipe_desc(struct account *a, char *buf, size_t len)
183 fetch_imappipe_desc(struct account *a, char *buf, size_t len)
182184 {
183185 struct imap_data *data = a->data;
184186
2929 #include <unistd.h>
3030
3131 #include "fdm.h"
32
33 int maildir_connect(struct account *);
34 int maildir_disconnect(struct account *);
35 int maildir_poll(struct account *, u_int *);
36 int maildir_fetch(struct account *, struct mail *);
37 int maildir_delete(struct account *);
38 /* conflicts with deliver-maildir.c */
39 void maildir_desc2(struct account *, char *, size_t);
32 #include "fetch.h"
33
34 int fetch_maildir_connect(struct account *);
35 int fetch_maildir_disconnect(struct account *);
36 int fetch_maildir_poll(struct account *, u_int *);
37 int fetch_maildir_fetch(struct account *, struct mail *);
38 int fetch_maildir_delete(struct account *);
39 void fetch_maildir_desc(struct account *, char *, size_t);
4040
4141 int maildir_makepaths(struct account *);
4242 void maildir_freepaths(struct account *);
4343
44 struct fetch fetch_maildir = { { NULL, NULL },
45 NULL,
46 maildir_connect,
47 maildir_poll,
48 maildir_fetch,
49 NULL,
50 maildir_delete,
51 NULL,
52 maildir_disconnect,
53 NULL,
54 maildir_desc2
44 struct fetch fetch_maildir = {
45 { NULL, NULL },
46 NULL,
47 fetch_maildir_connect,
48 fetch_maildir_poll,
49 fetch_maildir_fetch,
50 NULL,
51 fetch_maildir_delete,
52 NULL,
53 fetch_maildir_disconnect,
54 NULL,
55 fetch_maildir_desc
5556 };
5657
5758 /* Make an array of all the paths to visit. */
140141 }
141142
142143 int
143 maildir_connect(struct account *a)
144 fetch_maildir_connect(struct account *a)
144145 {
145146 struct maildir_data *data = a->data;
146147
156157 }
157158
158159 int
159 maildir_poll(struct account *a, u_int *n)
160 fetch_maildir_poll(struct account *a, u_int *n)
160161 {
161162 struct maildir_data *data = a->data;
162163 u_int i;
201202 }
202203
203204 int
204 maildir_fetch(struct account *a, struct mail *m)
205 fetch_maildir_fetch(struct account *a, struct mail *m)
205206 {
206207 struct maildir_data *data = a->data;
207208 struct dirent *dp;
294295 }
295296
296297 int
297 maildir_delete(struct account *a)
298 fetch_maildir_delete(struct account *a)
298299 {
299300 struct maildir_data *data = a->data;
300301
307308 }
308309
309310 int
310 maildir_disconnect(struct account *a)
311 fetch_maildir_disconnect(struct account *a)
311312 {
312313 struct maildir_data *data = a->data;
313314
320321 }
321322
322323 void
323 maildir_desc2(struct account *a, char *buf, size_t len)
324 fetch_maildir_desc(struct account *a, char *buf, size_t len)
324325 {
325326 struct maildir_data *data = a->data;
326327 char *maildirs;
2626 #include <unistd.h>
2727
2828 #include "fdm.h"
29
30 int nntp_init(struct account *);
31 int nntp_free(struct account *);
32 int nntp_connect(struct account *);
33 int nntp_disconnect(struct account *);
34 int nntp_poll(struct account *, u_int *);
35 int nntp_fetch(struct account *, struct mail *);
36 int nntp_delete(struct account *);
37 int nntp_keep(struct account *);
38 void nntp_desc(struct account *, char *, size_t);
29 #include "fetch.h"
30
31 int fetch_nntp_init(struct account *);
32 int fetch_nntp_free(struct account *);
33 int fetch_nntp_connect(struct account *);
34 int fetch_nntp_disconnect(struct account *);
35 int fetch_nntp_poll(struct account *, u_int *);
36 int fetch_nntp_fetch(struct account *, struct mail *);
37 int fetch_nntp_delete(struct account *);
38 int fetch_nntp_keep(struct account *);
39 void fetch_nntp_desc(struct account *, char *, size_t);
3940
4041 int nntp_code(char *);
4142 char *nntp_line(struct account *, char **, size_t *);
4647 int nntp_load(struct account *);
4748 int nntp_save(struct account *);
4849
49 struct fetch fetch_nntp = { { "nntp", NULL },
50 nntp_init,
51 nntp_connect,
52 nntp_poll,
53 nntp_fetch,
54 nntp_save,
55 NULL,
56 NULL,
57 nntp_disconnect,
58 nntp_free,
59 nntp_desc
50 struct fetch fetch_nntp = {
51 { "nntp", NULL },
52 fetch_nntp_init,
53 fetch_nntp_connect,
54 fetch_nntp_poll,
55 fetch_nntp_fetch,
56 nntp_save,
57 NULL,
58 NULL,
59 fetch_nntp_disconnect,
60 fetch_nntp_free,
61 fetch_nntp_desc
6062 };
6163
6264 int
362364 }
363365
364366 int
365 nntp_init(struct account *a)
367 fetch_nntp_init(struct account *a)
366368 {
367369 struct nntp_data *data = a->data;
368370 struct nntp_group *group;
383385 }
384386
385387 int
386 nntp_free(struct account *a)
388 fetch_nntp_free(struct account *a)
387389 {
388390 struct nntp_data *data = a->data;
389391 struct nntp_group *group;
402404 }
403405
404406 int
405 nntp_connect(struct account *a)
407 fetch_nntp_connect(struct account *a)
406408 {
407409 struct nntp_data *data = a->data;
408410 char *lbuf, *line, *cause;
455457 }
456458
457459 int
458 nntp_disconnect(struct account *a)
460 fetch_nntp_disconnect(struct account *a)
459461 {
460462 struct nntp_data *data = a->data;
461463 char *lbuf, *line;
488490 }
489491
490492 int
491 nntp_poll(struct account *a, u_int *n)
493 fetch_nntp_poll(struct account *a, u_int *n)
492494 {
493495 struct nntp_data *data = a->data;
494496 char *lbuf;
519521 }
520522
521523 int
522 nntp_fetch(struct account *a, struct mail *m)
524 fetch_nntp_fetch(struct account *a, struct mail *m)
523525 {
524526 struct nntp_data *data = a->data;
525527 struct nntp_group *group;
619621 }
620622
621623 void
622 nntp_desc(struct account *a, char *buf, size_t len)
624 fetch_nntp_desc(struct account *a, char *buf, size_t len)
623625 {
624626 struct nntp_data *data = a->data;
625627 char *names;
2424 #include <unistd.h>
2525
2626 #include "fdm.h"
27
28 int pop3_init(struct account *);
29 int pop3_free(struct account *);
30 int pop3_connect(struct account *);
31 int pop3_disconnect(struct account *);
32 int pop3_poll(struct account *, u_int *);
33 int pop3_fetch(struct account *, struct mail *);
34 int pop3_purge(struct account *);
35 int pop3_delete(struct account *);
36 int pop3_keep(struct account *);
37 void pop3_desc(struct account *, char *, size_t);
27 #include "fetch.h"
28
29 int fetch_pop3_init(struct account *);
30 int fetch_pop3_free(struct account *);
31 int fetch_pop3_connect(struct account *);
32 int fetch_pop3_disconnect(struct account *);
33 int fetch_pop3_poll(struct account *, u_int *);
34 int fetch_pop3_fetch(struct account *, struct mail *);
35 int fetch_pop3_purge(struct account *);
36 int fetch_pop3_delete(struct account *);
37 int fetch_pop3_keep(struct account *);
38 void fetch_pop3_desc(struct account *, char *, size_t);
3839
3940 char *pop3_line(struct account *, char **, size_t *);
4041 char *pop3_check(struct account *, char **, size_t *);
4142
42 struct fetch fetch_pop3 = { { "pop3", "pop3s" },
43 pop3_init,
44 pop3_connect,
45 pop3_poll,
46 pop3_fetch,
47 pop3_purge,
48 pop3_delete,
49 pop3_keep,
50 pop3_disconnect,
51 pop3_free,
52 pop3_desc
43 struct fetch fetch_pop3 = {
44 { "pop3", "pop3s" },
45 fetch_pop3_init,
46 fetch_pop3_connect,
47 fetch_pop3_poll,
48 fetch_pop3_fetch,
49 fetch_pop3_purge,
50 fetch_pop3_delete,
51 fetch_pop3_keep,
52 fetch_pop3_disconnect,
53 fetch_pop3_free,
54 fetch_pop3_desc
5355 };
5456
5557 char *
8890 }
8991
9092 int
91 pop3_free(struct account *a)
93 fetch_pop3_free(struct account *a)
9294 {
9395 struct pop3_data *data = a->data;
9496 u_int i;
104106 }
105107
106108 int
107 pop3_init(struct account *a)
109 fetch_pop3_init(struct account *a)
108110 {
109111 struct pop3_data *data = a->data;
110112
114116 }
115117
116118 int
117 pop3_connect(struct account *a)
119 fetch_pop3_connect(struct account *a)
118120 {
119121 struct pop3_data *data = a->data;
120122 char *lbuf, *line, *cause;
169171 }
170172
171173 int
172 pop3_disconnect(struct account *a)
174 fetch_pop3_disconnect(struct account *a)
173175 {
174176 struct pop3_data *data = a->data;
175177 char *lbuf;
200202 }
201203
202204 int
203 pop3_poll(struct account *a, u_int *n)
205 fetch_pop3_poll(struct account *a, u_int *n)
204206 {
205207 struct pop3_data *data = a->data;
206208
210212 }
211213
212214 int
213 pop3_fetch(struct account *a, struct mail *m)
215 fetch_pop3_fetch(struct account *a, struct mail *m)
214216 {
215217 struct pop3_data *data = a->data;
216218 char *lbuf, *line, *uid;
356358 }
357359
358360 int
359 pop3_purge(struct account *a)
360 {
361 if (pop3_disconnect(a) != 0)
361 fetch_pop3_purge(struct account *a)
362 {
363 if (fetch_pop3_disconnect(a) != 0)
362364 return (1);
363 return (pop3_connect(a));
364 }
365
366 int
367 pop3_delete(struct account *a)
365 return (fetch_pop3_connect(a));
366 }
367
368 int
369 fetch_pop3_delete(struct account *a)
368370 {
369371 struct pop3_data *data = a->data;
370372 char *lbuf;
386388 }
387389
388390 int
389 pop3_keep(struct account *a)
391 fetch_pop3_keep(struct account *a)
390392 {
391393 struct pop3_data *data = a->data;
392394
396398 }
397399
398400 void
399 pop3_desc(struct account *a, char *buf, size_t len)
401 fetch_pop3_desc(struct account *a, char *buf, size_t len)
400402 {
401403 struct pop3_data *data = a->data;
402404
2525 #include <unistd.h>
2626
2727 #include "fdm.h"
28 #include "fetch.h"
2829
29 int stdin_connect(struct account *);
30 int stdin_disconnect(struct account *);
31 int stdin_fetch(struct account *, struct mail *);
32 int stdin_delete(struct account *);
33 void stdin_desc(struct account *, char *, size_t);
30 int fetch_stdin_connect(struct account *);
31 int fetch_stdin_disconnect(struct account *);
32 int fetch_stdin_fetch(struct account *, struct mail *);
33 int fetch_stdin_delete(struct account *);
34 void fetch_stdin_desc(struct account *, char *, size_t);
3435
35 struct fetch fetch_stdin = { { NULL, NULL },
36 NULL,
37 stdin_connect,
38 NULL,
39 stdin_fetch,
40 NULL,
41 stdin_delete,
42 NULL,
43 stdin_disconnect,
44 NULL,
45 stdin_desc
36 struct fetch fetch_stdin = {
37 { NULL, NULL },
38 NULL,
39 fetch_stdin_connect,
40 NULL,
41 fetch_stdin_fetch,
42 NULL,
43 fetch_stdin_delete,
44 NULL,
45 fetch_stdin_disconnect,
46 NULL,
47 fetch_stdin_desc
4648 };
4749
4850 int
49 stdin_connect(struct account *a)
51 fetch_stdin_connect(struct account *a)
5052 {
5153 struct stdin_data *data = a->data;
5254
7274 }
7375
7476 int
75 stdin_disconnect(struct account *a)
77 fetch_stdin_disconnect(struct account *a)
7678 {
7779 struct stdin_data *data = a->data;
7880
8486 }
8587
8688 int
87 stdin_delete(struct account *a)
89 fetch_stdin_delete(struct account *a)
8890 {
8991 struct stdin_data *data = a->data;
9092 char *line, *lbuf;
101103 }
102104
103105 int
104 stdin_fetch(struct account *a, struct mail *m)
106 fetch_stdin_fetch(struct account *a, struct mail *m)
105107 {
106108 struct stdin_data *data = a->data;
107109 u_int lines;
180182 }
181183
182184 void
183 stdin_desc(unused struct account *a, char *buf, size_t len)
185 fetch_stdin_desc(unused struct account *a, char *buf, size_t len)
184186 {
185187 strlcpy(buf, "stdin", len);
186188 }
0 /* $Id$ */
1
2 /*
3 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
14 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
15 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #ifndef FETCH_H
19 #define FETCH_H
20
21 /* Poll return codes. */
22 #define POLL_SUCCESS FETCH_SUCCESS
23 #define POLL_ERROR FETCH_ERROR
24
25 /* Fetch return codes. */
26 #define FETCH_SUCCESS 0
27 #define FETCH_ERROR 1
28 #define FETCH_OVERSIZE 2
29 #define FETCH_COMPLETE 3
30
31 /* Fetch functions. */
32 struct fetch {
33 const char *ports[2]; /* normal port, ssl port */
34
35 int (*init)(struct account *);
36 int (*connect)(struct account *);
37 int (*poll)(struct account *, u_int *);
38 int (*fetch)(struct account *, struct mail *);
39 int (*purge)(struct account *);
40 int (*delete)(struct account *);
41 int (*keep)(struct account *);
42 int (*disconnect)(struct account *);
43 int (*free)(struct account *);
44 void (*desc)(struct account *, char *, size_t);
45 };
46
47 /* Fetch maildir data. */
48 struct maildir_data {
49 struct strings *maildirs;
50
51 struct strings *paths;
52 u_int index;
53
54 DIR *dirp;
55 char *path;
56 char entry[MAXPATHLEN];
57 char maildir[MAXPATHLEN];
58 };
59
60 /* NNTP group entry. */
61 struct nntp_group {
62 char *name;
63 int ignore;
64
65 u_int size;
66 u_int last;
67 char *id;
68 };
69
70 /* NNTP group list. */
71 ARRAY_DECL(nntp_groups, struct nntp_group *);
72
73 /* Fetch nntp data. */
74 struct nntp_data {
75 char *path;
76
77 struct server server;
78 struct strings *names;
79
80 u_int group;
81 struct nntp_groups groups;
82
83 struct io *io;
84 };
85 #define GET_GROUP(d, i) ARRAY_ITEM(&d->groups, i, struct nntp_group *)
86 #define CURRENT_GROUP(d) GET_GROUP(d, d->group)
87 #define TOTAL_GROUPS(d) ARRAY_LENGTH(&d->groups)
88 #define ADD_GROUP(d, g) ARRAY_ADD(&d->groups, g, struct nntp_group *)
89
90 /* Fetch stdin data. */
91 struct stdin_data {
92 int complete;
93
94 struct io *io;
95 };
96
97 /* Fetch pop3 data. */
98 struct pop3_data {
99 char *user;
100 char *pass;
101
102 struct server server;
103
104 u_int cur;
105 u_int num;
106
107 char *uid;
108 struct strings kept;
109
110 struct io *io;
111 };
112
113 /* IMAP tag types. */
114 #define IMAP_TAG_NONE -1
115 #define IMAP_TAG_CONTINUE -2
116 #define IMAP_TAG_ERROR -3
117
118 /* IMAP line types. */
119 #define IMAP_TAGGED 0
120 #define IMAP_CONTINUE 1
121 #define IMAP_UNTAGGED 2
122 #define IMAP_RAW 3
123
124 /* Fetch imap data. */
125 struct imap_data {
126 struct server server;
127 char *pipecmd;
128
129 struct io *io;
130 struct cmd *cmd;
131
132 char *user;
133 char *pass;
134 char *folder;
135
136 int tag;
137 u_int cur;
138 u_int num;
139
140 u_int uid;
141 ARRAY_DECL(, u_int) kept;
142
143 char *src;
144
145 size_t llen;
146 char *lbuf;
147
148 char *(*getln)(struct account *a, int);
149 int (*putln)(struct account *a, const char *, ...);
150 void (*flush)(struct account *a);
151 };
152
153 /* fetch-maildir.c */
154 extern struct fetch fetch_maildir;
155
156 /* fetch-stdin.c */
157 extern struct fetch fetch_stdin;
158
159 /* fetch-nntp.c */
160 extern struct fetch fetch_nntp;
161
162 /* fetch-pop3.c */
163 extern struct fetch fetch_pop3;
164
165 /* fetch-imap.c */
166 extern struct fetch fetch_imap;
167
168 /* fetch-imappipe.c */
169 extern struct fetch fetch_imappipe;
170
171 #endif
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "fetch.h"
2324
2425 int imap_okay(struct account *, char *);
2526
2222 #include <string.h>
2323
2424 #include "fdm.h"
25 #include "match.h"
2526
26 int age_match(struct match_ctx *, struct expritem *);
27 void age_desc(struct expritem *, char *, size_t);
27 int match_age_match(struct match_ctx *, struct expritem *);
28 void match_age_desc(struct expritem *, char *, size_t);
2829
2930 int age_tzlookup(const char *, int *);
3031
31 struct match match_age = { age_match, age_desc };
32 struct match match_age = {
33 match_age_match,
34 match_age_desc
35 };
3236
3337 /*
3438 * Some mailers, notably AOL's, use the timezone string instead of an offset
7478 }
7579
7680 int
77 age_match(struct match_ctx *mctx, struct expritem *ei)
81 match_age_match(struct match_ctx *mctx, struct expritem *ei)
7882 {
7983 struct age_data *data = ei->data;
8084 struct account *a = mctx->account;
167171 }
168172
169173 void
170 age_desc(struct expritem *ei, char *buf, size_t len)
174 match_age_desc(struct expritem *ei, char *buf, size_t len)
171175 {
172176 struct age_data *data = ei->data;
173177 const char *cmp = "";
2020 #include <fnmatch.h>
2121
2222 #include "fdm.h"
23 #include "match.h"
2324
24 int attachment_match(struct match_ctx *, struct expritem *);
25 void attachment_desc(struct expritem *, char *, size_t);
25 int match_attachment_match(struct match_ctx *, struct expritem *);
26 void match_attachment_desc(struct expritem *, char *, size_t);
2627
27 struct match match_attachment = { attachment_match, attachment_desc };
28 struct match match_attachment = {
29 match_attachment_match,
30 match_attachment_desc
31 };
2832
2933 int
30 attachment_match(struct match_ctx *mctx, struct expritem *ei)
34 match_attachment_match(struct match_ctx *mctx, struct expritem *ei)
3135 {
3236 struct attachment_data *data = ei->data;
3337 struct account *a = mctx->account;
142146 }
143147
144148 void
145 attachment_desc(struct expritem *ei, char *buf, size_t len)
149 match_attachment_desc(struct expritem *ei, char *buf, size_t len)
146150 {
147151 struct attachment_data *data = ei->data;
148152 const char *cmp = "";
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "match.h"
2324
24 int command_match(struct match_ctx *, struct expritem *);
25 void command_desc(struct expritem *, char *, size_t);
25 int match_command_match(struct match_ctx *, struct expritem *);
26 void match_command_desc(struct expritem *, char *, size_t);
2627
27 struct match match_command = { command_match, command_desc };
28 struct match match_command = {
29 match_command_match,
30 match_command_desc
31 };
2832
2933 int
30 command_match(struct match_ctx *mctx, struct expritem *ei)
34 match_command_match(struct match_ctx *mctx, struct expritem *ei)
3135 {
3236 struct command_data *data = ei->data;
3337 struct account *a = mctx->account;
5963 }
6064
6165 void
62 command_desc(struct expritem *ei, char *buf, size_t len)
66 match_command_desc(struct expritem *ei, char *buf, size_t len)
6367 {
6468 struct command_data *data = ei->data;
6569 char ret[11];
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "match.h"
2324
24 int matched_match(struct match_ctx *, struct expritem *);
25 void matched_desc(struct expritem *, char *, size_t);
25 int match_matched_match(struct match_ctx *, struct expritem *);
26 void match_matched_desc(struct expritem *, char *, size_t);
2627
27 struct match match_matched = { matched_match, matched_desc };
28 struct match match_matched = {
29 match_matched_match,
30 match_matched_desc
31 };
2832
2933 int
30 matched_match(struct match_ctx *mctx, unused struct expritem *ei)
34 match_matched_match(struct match_ctx *mctx, unused struct expritem *ei)
3135 {
3236 if (mctx->matched)
3337 return (MATCH_TRUE);
3539 }
3640
3741 void
38 matched_desc(unused struct expritem *ei, char *buf, size_t len)
42 match_matched_desc(unused struct expritem *ei, char *buf, size_t len)
3943 {
4044 strlcpy(buf, "matched", len);
4145 }
2020 #include <regex.h>
2121
2222 #include "fdm.h"
23 #include "match.h"
2324
24 int regexp_match(struct match_ctx *, struct expritem *);
25 void regexp_desc(struct expritem *, char *, size_t);
25 int match_regexp_match(struct match_ctx *, struct expritem *);
26 void match_regexp_desc(struct expritem *, char *, size_t);
2627
27 struct match match_regexp = { regexp_match, regexp_desc };
28 struct match match_regexp = {
29 match_regexp_match,
30 match_regexp_desc
31 };
2832
2933 int
30 regexp_match(struct match_ctx *mctx, struct expritem *ei)
34 match_regexp_match(struct match_ctx *mctx, struct expritem *ei)
3135 {
3236 struct regexp_data *data = ei->data;
3337 struct account *a = mctx->account;
7175 }
7276
7377 void
74 regexp_desc(struct expritem *ei, char *buf, size_t len)
78 match_regexp_desc(struct expritem *ei, char *buf, size_t len)
7579 {
7680 struct regexp_data *data = ei->data;
7781 const char *area = NULL;
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "match.h"
2324
24 int size_match(struct match_ctx *, struct expritem *);
25 void size_desc(struct expritem *, char *, size_t);
25 int match_size_match(struct match_ctx *, struct expritem *);
26 void match_size_desc(struct expritem *, char *, size_t);
2627
27 struct match match_size = { size_match, size_desc };
28 struct match match_size = {
29 match_size_match,
30 match_size_desc
31 };
2832
2933 int
30 size_match(struct match_ctx *mctx, struct expritem *ei)
34 match_size_match(struct match_ctx *mctx, struct expritem *ei)
3135 {
3236 struct size_data *data = ei->data;
3337 struct mail *m = mctx->mail;
4044 }
4145
4246 void
43 size_desc(struct expritem *ei, char *buf, size_t len)
47 match_size_desc(struct expritem *ei, char *buf, size_t len)
4448 {
4549 struct size_data *data = ei->data;
4650 const char *cmp = "";
2121 #include <string.h>
2222
2323 #include "fdm.h"
24 #include "match.h"
2425
25 int string_match(struct match_ctx *, struct expritem *);
26 void string_desc(struct expritem *, char *, size_t);
26 int match_string_match(struct match_ctx *, struct expritem *);
27 void match_string_desc(struct expritem *, char *, size_t);
2728
28 struct match match_string = { string_match, string_desc };
29 struct match match_string = {
30 match_string_match,
31 match_string_desc
32 };
2933
3034 int
31 string_match(struct match_ctx *mctx, struct expritem *ei)
35 match_string_match(struct match_ctx *mctx, struct expritem *ei)
3236 {
3337 struct string_data *data = ei->data;
3438 struct account *a = mctx->account;
5963 }
6064
6165 void
62 string_desc(struct expritem *ei, char *buf, size_t len)
66 match_string_desc(struct expritem *ei, char *buf, size_t len)
6367 {
6468 struct string_data *data = ei->data;
6569
2121 #include <string.h>
2222
2323 #include "fdm.h"
24 #include "match.h"
2425
25 int tagged_match(struct match_ctx *, struct expritem *);
26 void tagged_desc(struct expritem *, char *, size_t);
26 int match_tagged_match(struct match_ctx *, struct expritem *);
27 void match_tagged_desc(struct expritem *, char *, size_t);
2728
28 struct match match_tagged = { tagged_match, tagged_desc };
29 struct match match_tagged = {
30 match_tagged_match,
31 match_tagged_desc
32 };
2933
3034 int
31 tagged_match(struct match_ctx *mctx, struct expritem *ei)
35 match_tagged_match(struct match_ctx *mctx, struct expritem *ei)
3236 {
3337 struct tagged_data *data = ei->data;
3438 struct mail *m = mctx->mail;
3943 }
4044
4145 void
42 tagged_desc(struct expritem *ei, char *buf, size_t len)
46 match_tagged_desc(struct expritem *ei, char *buf, size_t len)
4347 {
4448 struct tagged_data *data = ei->data;
4549
2020 #include <string.h>
2121
2222 #include "fdm.h"
23 #include "match.h"
2324
24 int unmatched_match(struct match_ctx *, struct expritem *);
25 void unmatched_desc(struct expritem *, char *, size_t);
25 int match_unmatched_match(struct match_ctx *, struct expritem *);
26 void match_unmatched_desc(struct expritem *, char *, size_t);
2627
27 struct match match_unmatched = { unmatched_match, unmatched_desc };
28 struct match match_unmatched = {
29 match_unmatched_match,
30 match_unmatched_desc
31 };
2832
2933 int
30 unmatched_match(struct match_ctx *mctx, unused struct expritem *ei)
34 match_unmatched_match(struct match_ctx *mctx, unused struct expritem *ei)
3135 {
3236 if (mctx->matched)
3337 return (MATCH_FALSE);
3539 }
3640
3741 void
38 unmatched_desc(unused struct expritem *ei, char *buf, size_t len)
42 match_unmatched_desc(unused struct expritem *ei, char *buf, size_t len)
3943 {
4044 strlcpy(buf, "unmatched", len);
4145 }
0 /* $Id$ */
1
2 /*
3 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
14 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
15 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #ifndef MATCH_H
19 #define MATCH_H
20
21 /* Match return codes. */
22 #define MATCH_FALSE 0
23 #define MATCH_TRUE 1
24 #define MATCH_ERROR 2
25
26 /* Match context. */
27 struct match_ctx {
28 struct io *io;
29 struct account *account;
30 struct mail *mail;
31
32 enum decision decision;
33
34 int matched;
35 int stopped;
36
37 int pm_valid;
38 regmatch_t pm[NPMATCH];
39 };
40
41 /* Match functions. */
42 struct match {
43 int (*match)(struct match_ctx *, struct expritem *);
44 void (*desc)(struct expritem *, char *, size_t);
45 };
46
47 /* Match attachment data. */
48 struct attachment_data {
49 enum {
50 ATTACHOP_COUNT,
51 ATTACHOP_TOTALSIZE,
52 ATTACHOP_ANYSIZE,
53 ATTACHOP_ANYTYPE,
54 ATTACHOP_ANYNAME
55 } op;
56
57 enum cmp cmp;
58 union {
59 size_t size;
60 long long num;
61 char *str;
62 struct re re;
63 } value;
64 };
65
66 /* Match age data. */
67 struct age_data {
68 long long time;
69 enum cmp cmp;
70 };
71
72 /* Match size data. */
73 struct size_data {
74 size_t size;
75 enum cmp cmp;
76 };
77
78 /* Match tagged data. */
79 struct tagged_data {
80 char *tag;
81 };
82
83 /* Match string data. */
84 struct string_data {
85 struct re re;
86
87 char *str;
88 };
89
90 /* Match regexp data. */
91 struct regexp_data {
92 struct re re;
93
94 enum area area;
95 };
96
97 /* Match command data. */
98 struct command_data {
99 char *cmd;
100 uid_t uid;
101 int pipe; /* pipe mail to command */
102
103 struct re re; /* re->re NULL to not check */
104 int ret; /* -1 to not check */
105 };
106
107 /* match-age.c */
108 extern struct match match_age;
109
110 /* match-attachment.c */
111 extern struct match match_attachment;
112
113 /* match-matched.c */
114 extern struct match match_matched;
115
116 /* match-unmatched.c */
117 extern struct match match_unmatched;
118
119 /* match-size.c */
120 extern struct match match_size;
121
122 /* match-tagged.c */
123 extern struct match match_tagged;
124
125 /* match-string.c */
126 extern struct match match_string;
127
128 /* match-command.c */
129 extern struct match match_command;
130
131 /* match-regexp.c */
132 extern struct match match_regexp;
133
134 #endif
2525 #include <unistd.h>
2626
2727 #include "fdm.h"
28 #include "deliver.h"
29 #include "match.h"
2830
2931 int parent_action(struct action *, struct deliver_ctx *, uid_t);
3032 int parent_command(struct match_ctx *, struct command_data *, uid_t);
3737 #include <unistd.h>
3838
3939 #include "fdm.h"
40 #include "deliver.h"
41 #include "fetch.h"
42 #include "match.h"
4043
4144 struct macros macros = TAILQ_HEAD_INITIALIZER(macros);
4245 u_int ruleidx;