ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CreditCardReminder/CreditCardReminder.c
Revision: 742
Committed: 2006-04-06T21:20:38-07:00 (19 years, 3 months ago) by douglas
Content type: text/x-c
File size: 3947 byte(s)
Log Message:
God damn kids!

File Contents

# User Rev Content
1 douglas 740 // Credit Card Reminder
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 742 #include <setjmp.h>
8     #include <stdio.h>
9     #include <time.h>
10    
11 douglas 740 #include <c-client/c-client.h>
12    
13 douglas 742 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 douglas 740 int main(int argc, char *argv[])
38     {
39 douglas 742 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 douglas 740 # include <c-client/linkage.c>
62    
63 douglas 742 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 douglas 740 return 0;
76     }
77    
78     void mm_flags(MAILSTREAM *stream, unsigned long number)
79     {
80 douglas 742 printf("flags:\n number = %lu\n", number);
81 douglas 740 }
82    
83     void mm_status(MAILSTREAM *stream, char *mailbox, MAILSTATUS *status)
84     {
85 douglas 742 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 douglas 740 }
102    
103     void mm_searched(MAILSTREAM *stream, unsigned long number)
104     {
105 douglas 742 printf("searched:\n number = %lu\n", number);
106 douglas 740 }
107    
108     void mm_exists(MAILSTREAM *stream, unsigned long number)
109     {
110 douglas 742 printf("exists:\n number = %lu\n", number);
111 douglas 740 }
112    
113     void mm_expunged(MAILSTREAM *stream, unsigned long number)
114     {
115 douglas 742 printf("expunged:\n number = %lu\n", number);
116 douglas 740 }
117    
118     void mm_list(MAILSTREAM *stream, int delim, char *name, long attrib)
119     {
120 douglas 742 printf("list");
121 douglas 740 }
122    
123     void mm_lsub(MAILSTREAM *stream, int delim, char *name, long attrib)
124     {
125 douglas 742 printf("lsub");
126 douglas 740 }
127    
128     void mm_notify(MAILSTREAM *stream, char *string, long errflg)
129     {
130 douglas 742 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 douglas 740 }
136    
137     void mm_log(char *string, long errflg)
138     {
139 douglas 742 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 douglas 740 }
148    
149     void mm_dlog(char *string)
150     {
151 douglas 742 printf("dlog:\n string = %s\n", string);
152 douglas 740 }
153    
154     void mm_login(NETMBX *mb, char *user, char *pwd, long trial)
155     {
156 douglas 742 printf("login:\n trial = %li\n", trial);
157     strcpy(user, "douglas");
158     strcpy(pwd, getpass("password:"));
159 douglas 740 }
160    
161     void mm_critical(MAILSTREAM *stream)
162     {
163 douglas 742 printf("critical\n");
164 douglas 740 }
165    
166     void mm_nocritical(MAILSTREAM *stream)
167     {
168 douglas 742 printf("nocritical\n");
169 douglas 740 }
170    
171     long mm_diskerror(MAILSTREAM *stream, long errcode, long serious)
172     {
173 douglas 742 printf("diskerror:\n errcode = %li\n serious = %li\n", errcode, serious);
174    
175 douglas 740 return 1;
176     }
177    
178     void mm_fatal(char *string)
179     {
180 douglas 742 printf("fatal:\n string = %s\n", string);
181 douglas 740 }

Properties

Name Value
svn:eol-style native
svn:keywords Id