1 |
// Credit Card Reminder |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include <setjmp.h> |
8 |
#include <stdio.h> |
9 |
#include <time.h> |
10 |
|
11 |
#include <c-client/c-client.h> |
12 |
|
13 |
static char *error = NULL; |
14 |
|
15 |
MAILSTREAM *check(MAILSTREAM *value, jmp_buf environment) |
16 |
{ |
17 |
if (value == NIL) |
18 |
longjmp(environment, 2); |
19 |
|
20 |
return value; |
21 |
} |
22 |
|
23 |
unsigned short date(void) |
24 |
{ |
25 |
time_t now = time(NULL); |
26 |
struct tm date; |
27 |
|
28 |
gmtime_r(&now, &date); |
29 |
|
30 |
--date.tm_mon; |
31 |
|
32 |
timegm(&date); |
33 |
|
34 |
return ((date.tm_year + 1900 - BASEYEAR) << 9) + ((date.tm_mon + 1) << 5) + date.tm_mday; |
35 |
} |
36 |
|
37 |
int main(int argc, char *argv[]) |
38 |
{ |
39 |
int exception; |
40 |
jmp_buf environment; |
41 |
|
42 |
switch (exception = setjmp(environment)) |
43 |
{ |
44 |
case 0: |
45 |
break; |
46 |
case 1: |
47 |
perror(argv[0]); |
48 |
|
49 |
return 1; |
50 |
case 2: |
51 |
fprintf(stderr, "%s: %s\n", argv[0], error); |
52 |
free(error); |
53 |
|
54 |
return 1; |
55 |
default: |
56 |
fprintf(stderr, "%s: %s\n", argv[0], (char *)exception); |
57 |
|
58 |
return 1; |
59 |
} |
60 |
|
61 |
# include <c-client/linkage.c> |
62 |
|
63 |
MAILSTREAM *stream = check(mail_open(NIL, "{reptile.douglasthrift.net/novalidate-cert/tls}", OP_READONLY | OP_DEBUG), environment); |
64 |
STRINGLIST from = { .text = { .data = (unsigned char *)"wellsfargo.com", .size = 14 } }, body = { .text = { .data = (unsigned char *)" is due on ", .size = 11 } }; |
65 |
SEARCHPGM search = { .from = &from, .body = &body, .since = date() }; |
66 |
SORTPGM sort = { .reverse = 1, .function = SORTARRIVAL }; |
67 |
unsigned long *messages = mail_sort(stream, "ISO-8859-1", &search, &sort, SE_UID); |
68 |
|
69 |
for (unsigned long *message = messages; *message != 0; ++message) |
70 |
fprintf(stderr, "%lu\n", *message); |
71 |
|
72 |
fs_give((void *)&messages); |
73 |
mail_close(stream); |
74 |
|
75 |
return 0; |
76 |
} |
77 |
|
78 |
void mm_flags(MAILSTREAM *stream, unsigned long number) |
79 |
{ |
80 |
printf("flags:\n number = %lu\n", number); |
81 |
} |
82 |
|
83 |
void mm_status(MAILSTREAM *stream, char *mailbox, MAILSTATUS *status) |
84 |
{ |
85 |
printf("mailbox %s:\n", mailbox); |
86 |
|
87 |
if (status->flags & SA_MESSAGES) |
88 |
printf(" messages = %lu\n", status->messages); |
89 |
|
90 |
if (status->flags & SA_RECENT) |
91 |
printf(" recent = %lu\n", status->recent); |
92 |
|
93 |
if (status->flags & SA_UNSEEN) |
94 |
printf(" unseen = %lu\n", status->unseen); |
95 |
|
96 |
if (status->flags & SA_UIDNEXT) |
97 |
printf(" uidnext = %lu\n", status->uidnext); |
98 |
|
99 |
if (status->flags & SA_UIDVALIDITY) |
100 |
printf(" uidvalidity = %lu\n", status->uidvalidity); |
101 |
} |
102 |
|
103 |
void mm_searched(MAILSTREAM *stream, unsigned long number) |
104 |
{ |
105 |
printf("searched:\n number = %lu\n", number); |
106 |
} |
107 |
|
108 |
void mm_exists(MAILSTREAM *stream, unsigned long number) |
109 |
{ |
110 |
printf("exists:\n number = %lu\n", number); |
111 |
} |
112 |
|
113 |
void mm_expunged(MAILSTREAM *stream, unsigned long number) |
114 |
{ |
115 |
printf("expunged:\n number = %lu\n", number); |
116 |
} |
117 |
|
118 |
void mm_list(MAILSTREAM *stream, int delim, char *name, long attrib) |
119 |
{ |
120 |
printf("list"); |
121 |
} |
122 |
|
123 |
void mm_lsub(MAILSTREAM *stream, int delim, char *name, long attrib) |
124 |
{ |
125 |
printf("lsub"); |
126 |
} |
127 |
|
128 |
void mm_notify(MAILSTREAM *stream, char *string, long errflg) |
129 |
{ |
130 |
char *flag; |
131 |
|
132 |
asprintf(&flag, "%li", errflg); |
133 |
printf("notify %s:\n string = %s\n", errflg == NIL ? "NIL" : errflg == WARN ? "WARN" : errflg == ERROR ? "ERROR" : flag, string); |
134 |
free(flag); |
135 |
} |
136 |
|
137 |
void mm_log(char *string, long errflg) |
138 |
{ |
139 |
char *flag; |
140 |
|
141 |
asprintf(&flag, "%li", errflg); |
142 |
printf("log %s:\n string = %s\n", errflg == NIL ? "NIL" : errflg == PARSE ? "PARSE" : errflg == WARN ? "WARN" : errflg == ERROR ? "ERROR" : flag, string); |
143 |
free(flag); |
144 |
|
145 |
if (errflg == ERROR) |
146 |
asprintf(&error, "%s", string); |
147 |
} |
148 |
|
149 |
void mm_dlog(char *string) |
150 |
{ |
151 |
printf("dlog:\n string = %s\n", string); |
152 |
} |
153 |
|
154 |
void mm_login(NETMBX *mb, char *user, char *pwd, long trial) |
155 |
{ |
156 |
printf("login:\n trial = %li\n", trial); |
157 |
strcpy(user, "douglas"); |
158 |
strcpy(pwd, getpass("password:")); |
159 |
} |
160 |
|
161 |
void mm_critical(MAILSTREAM *stream) |
162 |
{ |
163 |
printf("critical\n"); |
164 |
} |
165 |
|
166 |
void mm_nocritical(MAILSTREAM *stream) |
167 |
{ |
168 |
printf("nocritical\n"); |
169 |
} |
170 |
|
171 |
long mm_diskerror(MAILSTREAM *stream, long errcode, long serious) |
172 |
{ |
173 |
printf("diskerror:\n errcode = %li\n serious = %li\n", errcode, serious); |
174 |
|
175 |
return 1; |
176 |
} |
177 |
|
178 |
void mm_fatal(char *string) |
179 |
{ |
180 |
printf("fatal:\n string = %s\n", string); |
181 |
} |