A stub mail.remote. It is waiting on completion of the smtp mailer_t.
Showing
2 changed files
with
127 additions
and
0 deletions
mail.remote/Makefile.am
0 → 100644
mail.remote/mail.remote.c
0 → 100644
1 | /* FIXME: the will no really work until I've completed the smtp mailer_t. | ||
2 | Until then, its just place holder code. | ||
3 | */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/stat.h> | ||
7 | |||
8 | #include <errno.h> | ||
9 | #include <stdio.h> | ||
10 | #include <string.h> | ||
11 | #include <stdlib.h> | ||
12 | #include <unistd.h> | ||
13 | |||
14 | #include <mailutils/address.h> | ||
15 | #include <mailutils/debug.h> | ||
16 | #include <mailutils/errno.h> | ||
17 | #include <mailutils/list.h> | ||
18 | #include <mailutils/mailer.h> | ||
19 | #include <mailutils/message.h> | ||
20 | #include <mailutils/registrar.h> | ||
21 | #include <mailutils/stream.h> | ||
22 | |||
23 | #define C(X) {int e; if((e = X) != 0) { \ | ||
24 | fprintf(stderr, "%s failed: %s\n", #X, mu_errstring(e)); \ | ||
25 | exit(1); } } | ||
26 | |||
27 | const char USAGE[] = | ||
28 | "usage: mailer [-hd] [-m mailer] [-f from] [to]..." | ||
29 | ; | ||
30 | const char HELP[] = | ||
31 | " -h print this helpful message\n" | ||
32 | " -m a mailer URL (default is \"sendmail:\")\n" | ||
33 | " -f the envelope from address (default is from user environment)\n" | ||
34 | " to a list of envelope to addresses (default is from message)\n" | ||
35 | "\n" | ||
36 | "An RFC2822 formatted message is read from stdin and delivered using\n" | ||
37 | "the mailer.\n" | ||
38 | ; | ||
39 | |||
40 | int | ||
41 | main (int argc, char *argv[]) | ||
42 | { | ||
43 | int opt; | ||
44 | int optdebug = 0; | ||
45 | char* optmailer = "sendmail:"; | ||
46 | char* optfrom = 0; | ||
47 | |||
48 | stream_t in = 0; | ||
49 | message_t msg = 0; | ||
50 | mailer_t mailer = 0; | ||
51 | address_t from = 0; | ||
52 | address_t to = 0; | ||
53 | |||
54 | while((opt = getopt(argc, argv, "hdm:f:")) != -1) | ||
55 | { | ||
56 | switch(opt) | ||
57 | { | ||
58 | case 'h': | ||
59 | printf("%s\n%s", USAGE, HELP); | ||
60 | return 0; | ||
61 | case 'd': | ||
62 | optdebug++; | ||
63 | break; | ||
64 | case 'm': | ||
65 | optmailer = optarg; | ||
66 | break; | ||
67 | case 'f': | ||
68 | optfrom = optarg; | ||
69 | break; | ||
70 | default: | ||
71 | fprintf(stderr, "%s\n", USAGE); | ||
72 | break; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | /* Register mailers. */ | ||
77 | { | ||
78 | list_t bookie; | ||
79 | registrar_get_list (&bookie); | ||
80 | C( list_append (bookie, smtp_record) ) | ||
81 | C( list_append (bookie, sendmail_record) ) | ||
82 | } | ||
83 | |||
84 | if(optfrom) | ||
85 | { | ||
86 | C( address_create(&from, optfrom) ) | ||
87 | } | ||
88 | |||
89 | if(argv[optind]) | ||
90 | { | ||
91 | char** av = argv + optind; | ||
92 | |||
93 | C( address_createv(&to, (const char**) av, -1) ) | ||
94 | } | ||
95 | |||
96 | C( stdio_stream_create(&in, stdin, 0) ) | ||
97 | |||
98 | C( stream_open(in) ) | ||
99 | |||
100 | C( message_create (&msg, NULL) ) | ||
101 | |||
102 | C( message_set_stream(msg, in, NULL) ) | ||
103 | |||
104 | C( mailer_create(&mailer, optmailer) ) | ||
105 | |||
106 | if(optdebug) | ||
107 | { | ||
108 | mu_debug_t debug; | ||
109 | mailer_get_debug (mailer, &debug); | ||
110 | mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT); | ||
111 | } | ||
112 | |||
113 | C( mailer_open(mailer, 0) ) | ||
114 | |||
115 | C( mailer_send_message(mailer, msg, from, to) ) | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 |
-
Please register or sign in to post a comment