ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/Mail/SpamUpdate.pl
(Generate patch)

Comparing FreeBSDAdmin/Mail/SpamUpdate.c (file contents):
Revision 836 by douglas, 2006-07-10T00:55:02-07:00 vs.
Revision 912 by douglas, 2007-05-03T15:46:15-07:00

# Line 14 | Line 14
14  
15   #include <c-client/c-client.h>
16  
17 < #define NEGATIVE "Spam/False Negative"
18 < #define POSITIVE "Spam/False Positive"
17 > #define NEGATIVE "Spam.False Negative"
18 > #define POSITIVE "Spam.False Positive"
19 >
20 > #define SERVER "{mail.douglasthrift.net/tls/novalidate-cert}"
21  
22   #define SPAMC "/usr/local/bin/spamc"
23   #define SPAMD "/var/run/spamd/spamd.sock"
# Line 30 | Line 32 | static MAILSTREAM *streams[2];
32   static uint8_t critical = 0;
33   static unsigned long *messages[] = { NULL, NULL };
34   static size_t counts[] = { 0, 0 };
35 + static char *pass;
36  
37   static int check(int value, jmp_buf environment)
38   {
# Line 70 | Line 73 | static char *fcheck(char *value, FILE *s
73   static void learn()
74   {
75          typedef struct { const char *verb, *learn, *collab, *mailbox; } Job;
76 <        
76 >
77          Job jobs[] = { { .verb = "report", .learn = "spam", .collab = "report", .mailbox = NEGATIVE }, { .verb = "revok", .learn = "ham", .collab = "revoke", .mailbox = POSITIVE } };
78  
79          for (Job *job = jobs; job != jobs + sizeof (jobs) / sizeof (*jobs); ++job)
# Line 78 | Line 81 | static void learn()
81                  printf("\nLearning and %sing from the %s mailbox:\n", job->verb, job->mailbox);
82  
83                  SEARCHPGM search = { .undeleted = 1 };
84 <                
84 >
85                  mail_search_full(streams[job - jobs], NIL, &search, SE_UID);
86  
87                  const unsigned long *messages_ = messages[job - jobs];
# Line 164 | Line 167 | void delete()
167  
168                  const unsigned long *messages_ = messages[mailbox - mailboxes];
169                  const size_t count = counts[mailbox - mailboxes];
167                char *sequence = calloc(1, sizeof (char));
168                size_t size = 1;
170  
171 <                for (size_t index = 0; index != count; ++index)
171 >                if (count)
172                  {
173 <                        char *message;
173 >                        char *sequence = calloc(1, sizeof (char));
174 >                        size_t size = 1;
175  
176 <                        asprintf(&message, "%lu%s", messages_[index], index + 1 != count ? "," : "");
176 >                        for (size_t index = 0; index != count; ++index)
177 >                        {
178 >                                char *message;
179 >
180 >                                asprintf(&message, "%lu%s", messages_[index], index + 1 != count ? "," : "");
181  
182 <                        sequence = realloc(sequence, (size += strlen(message)) * sizeof (char));
182 >                                sequence = realloc(sequence, (size += strlen(message)) * sizeof (char));
183 >
184 >                                strlcat(sequence, message, size);
185 >                                free(message);
186 >                        }
187  
188 <                        strlcat(sequence, message, size);
189 <                        free(message);
188 >                        mail_setflag_full(streams[mailbox - mailboxes], sequence, "\\Deleted", ST_UID | ST_SILENT);
189 >                        free(sequence);
190                  }
191  
182                mail_setflag_full(streams[mailbox - mailboxes], sequence, "\\Deleted", ST_UID | ST_SILENT);
183                free(sequence);
192                  printf("    %u message(s) marked deleted.\n", count);
193          }
194   }
# Line 214 | Line 222 | int main(int argc, char *argv[])
222                  else
223                          return printf("Usage: %s [-debug]\n", argv[0]), 1;
224  
225 <        printf("Information:\n    If you receive spam in your Inbox mailbox, copy it to the " NEGATIVE " mailbox.\n\n    If you receive mail that is not spam in your Spam/Assassin mailbox, copy it to the " POSITIVE " mailbox.\n");
225 >        printf("Information:\n    If you receive spam in your Inbox mailbox, copy it to the " NEGATIVE " mailbox.\n\n    If you receive mail that is not spam in your Spam mailbox, copy it to the " POSITIVE " mailbox.\n");
226  
227 +        check(asprintf(&pass, "%s/.CreditCardReminder.pass", getenv("HOME")), environment);
228          check(sigemptyset(&set), environment);
229          check(sigaddset(&set, SIGHUP), environment);
230          check(sigaddset(&set, SIGINT), environment);
231  
232   #       include <c-client/linkage.c>
233  
234 <        streams[0] = mcheck(mail_open(NIL, NEGATIVE, debug ? OP_DEBUG : 0), environment);
235 <        streams[1] = mcheck(mail_open(NIL, POSITIVE, debug ? OP_DEBUG : 0), environment);
234 >        streams[0] = mcheck(mail_open(NIL, SERVER NEGATIVE, debug ? OP_DEBUG : 0), environment);
235 >        streams[1] = mcheck(mail_open(NIL, SERVER POSITIVE, debug ? OP_DEBUG : 0), environment);
236  
237          learn();
238          delete();
# Line 309 | Line 318 | void mm_dlog(char *string)
318          fprintf(stderr, "%s\n", string);
319   }
320  
321 < void mm_login(NETMBX *mb, char *user, char *pwd, long trial) {}
321 > void mm_login(NETMBX *mb, char *user, char *pwd, long trial)
322 > {
323 >        strcpy(user, "douglas");
324 >
325 >        FILE *file = fopen(pass, "r");
326 >
327 >        if (!file)
328 >                longjmp(environment, 1);
329 >
330 >        size_t size;
331 >        char *line = fcheck(fgetln(file, &size), file, environment);
332 >
333 >        strlcpy(pwd, line, size);
334 > }
335  
336   void mm_critical(MAILSTREAM *stream)
337   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines