Merge pull request #1466 from rubenk/write_riemann-remove-unneeded-include
[collectd.git] / src / email.c
1 /**
2  * collectd - src/email.c
3  * Copyright (C) 2006-2008  Sebastian Harl
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *   Sebastian Harl <sh at tokkee.org>
25  **/
26
27 /*
28  * This plugin communicates with a spam filter, a virus scanner or similar
29  * software using a UNIX socket and a very simple protocol:
30  *
31  * e-mail type (e.g. ham, spam, virus, ...) and size
32  * e:<type>:<bytes>
33  *
34  * spam score
35  * s:<value>
36  *
37  * successful spam checks
38  * c:<type1>[,<type2>,...]
39  */
40
41 #include "collectd.h"
42 #include "common.h"
43 #include "plugin.h"
44
45 #include "configfile.h"
46
47 #include <stddef.h>
48
49 #if HAVE_LIBPTHREAD
50 # include <pthread.h>
51 #endif
52
53 #include <sys/un.h>
54 #include <sys/select.h>
55
56 /* some systems (e.g. Darwin) seem to not define UNIX_PATH_MAX at all */
57 #ifndef UNIX_PATH_MAX
58 # define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
59 #endif /* UNIX_PATH_MAX */
60
61 #if HAVE_GRP_H
62 #       include <grp.h>
63 #endif /* HAVE_GRP_H */
64
65 #define SOCK_PATH LOCALSTATEDIR"/run/"PACKAGE_NAME"-email"
66 #define MAX_CONNS 5
67 #define MAX_CONNS_LIMIT 16384
68
69 #define log_debug(...) DEBUG ("email: "__VA_ARGS__)
70 #define log_err(...) ERROR ("email: "__VA_ARGS__)
71 #define log_warn(...) WARNING ("email: "__VA_ARGS__)
72
73 /*
74  * Private data structures
75  */
76 /* linked list of email and check types */
77 typedef struct type {
78         char        *name;
79         int         value;
80         struct type *next;
81 } type_t;
82
83 typedef struct {
84         type_t *head;
85         type_t *tail;
86 } type_list_t;
87
88 /* collector thread control information */
89 typedef struct collector {
90         pthread_t thread;
91
92         /* socket descriptor of the current/last connection */
93         FILE *socket;
94 } collector_t;
95
96 /* linked list of pending connections */
97 typedef struct conn {
98         /* socket to read data from */
99         FILE *socket;
100
101         /* linked list of connections */
102         struct conn *next;
103 } conn_t;
104
105 typedef struct {
106         conn_t *head;
107         conn_t *tail;
108 } conn_list_t;
109
110 /*
111  * Private variables
112  */
113 /* valid configuration file keys */
114 static const char *config_keys[] =
115 {
116         "SocketFile",
117         "SocketGroup",
118         "SocketPerms",
119         "MaxConns"
120 };
121 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
122
123 /* socket configuration */
124 static char *sock_file  = NULL;
125 static char *sock_group = NULL;
126 static int  sock_perms  = S_IRWXU | S_IRWXG;
127 static int  max_conns   = MAX_CONNS;
128
129 /* state of the plugin */
130 static int disabled = 0;
131
132 /* thread managing "client" connections */
133 static pthread_t connector = (pthread_t) 0;
134 static int connector_socket = -1;
135
136 /* tell the collector threads that a new connection is available */
137 static pthread_cond_t conn_available = PTHREAD_COND_INITIALIZER;
138
139 /* connections that are waiting to be processed */
140 static pthread_mutex_t conns_mutex = PTHREAD_MUTEX_INITIALIZER;
141 static conn_list_t conns;
142
143 /* tell the connector thread that a collector is available */
144 static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER;
145
146 /* collector threads */
147 static collector_t **collectors = NULL;
148
149 static pthread_mutex_t available_mutex = PTHREAD_MUTEX_INITIALIZER;
150 static int available_collectors;
151
152 static pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
153 static type_list_t list_count;
154 static type_list_t list_count_copy;
155
156 static pthread_mutex_t size_mutex = PTHREAD_MUTEX_INITIALIZER;
157 static type_list_t list_size;
158 static type_list_t list_size_copy;
159
160 static pthread_mutex_t score_mutex = PTHREAD_MUTEX_INITIALIZER;
161 static double score;
162 static int score_count;
163
164 static pthread_mutex_t check_mutex = PTHREAD_MUTEX_INITIALIZER;
165 static type_list_t list_check;
166 static type_list_t list_check_copy;
167
168 /*
169  * Private functions
170  */
171 static int email_config (const char *key, const char *value)
172 {
173         if (0 == strcasecmp (key, "SocketFile")) {
174                 if (NULL != sock_file)
175                         free (sock_file);
176                 sock_file = sstrdup (value);
177         }
178         else if (0 == strcasecmp (key, "SocketGroup")) {
179                 if (NULL != sock_group)
180                         free (sock_group);
181                 sock_group = sstrdup (value);
182         }
183         else if (0 == strcasecmp (key, "SocketPerms")) {
184                 /* the user is responsible for providing reasonable values */
185                 sock_perms = (int)strtol (value, NULL, 8);
186         }
187         else if (0 == strcasecmp (key, "MaxConns")) {
188                 long int tmp = strtol (value, NULL, 0);
189
190                 if (tmp < 1) {
191                         fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
192                                         "value %li, will use default %i.\n",
193                                         tmp, MAX_CONNS);
194                         ERROR ("email plugin: `MaxConns' was set to invalid "
195                                         "value %li, will use default %i.\n",
196                                         tmp, MAX_CONNS);
197                         max_conns = MAX_CONNS;
198                 }
199                 else if (tmp > MAX_CONNS_LIMIT) {
200                         fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
201                                         "value %li, will use hardcoded limit %i.\n",
202                                         tmp, MAX_CONNS_LIMIT);
203                         ERROR ("email plugin: `MaxConns' was set to invalid "
204                                         "value %li, will use hardcoded limit %i.\n",
205                                         tmp, MAX_CONNS_LIMIT);
206                         max_conns = MAX_CONNS_LIMIT;
207                 }
208                 else {
209                         max_conns = (int)tmp;
210                 }
211         }
212         else {
213                 return -1;
214         }
215         return 0;
216 } /* static int email_config (char *, char *) */
217
218 /* Increment the value of the given name in the given list by incr. */
219 static void type_list_incr (type_list_t *list, char *name, int incr)
220 {
221         if (NULL == list->head) {
222                 list->head = (type_t *)smalloc (sizeof (type_t));
223
224                 list->head->name  = sstrdup (name);
225                 list->head->value = incr;
226                 list->head->next  = NULL;
227
228                 list->tail = list->head;
229         }
230         else {
231                 type_t *ptr;
232
233                 for (ptr = list->head; NULL != ptr; ptr = ptr->next) {
234                         if (0 == strcmp (name, ptr->name))
235                                 break;
236                 }
237
238                 if (NULL == ptr) {
239                         list->tail->next = (type_t *)smalloc (sizeof (type_t));
240                         list->tail = list->tail->next;
241
242                         list->tail->name  = sstrdup (name);
243                         list->tail->value = incr;
244                         list->tail->next  = NULL;
245                 }
246                 else {
247                         ptr->value += incr;
248                 }
249         }
250         return;
251 } /* static void type_list_incr (type_list_t *, char *) */
252
253 static void *collect (void *arg)
254 {
255         collector_t *this = (collector_t *)arg;
256
257         while (1) {
258                 conn_t *connection;
259
260                 pthread_mutex_lock (&conns_mutex);
261
262                 while (NULL == conns.head) {
263                         pthread_cond_wait (&conn_available, &conns_mutex);
264                 }
265
266                 connection = conns.head;
267                 conns.head = conns.head->next;
268
269                 if (NULL == conns.head) {
270                         conns.tail = NULL;
271                 }
272
273                 pthread_mutex_unlock (&conns_mutex);
274
275                 /* make the socket available to the global
276                  * thread and connection management */
277                 this->socket = connection->socket;
278
279                 log_debug ("collect: handling connection on fd #%i",
280                                 fileno (this->socket));
281
282                 while (42) {
283                         /* 256 bytes ought to be enough for anybody ;-) */
284                         char line[256 + 1]; /* line + '\0' */
285                         int  len = 0;
286
287                         errno = 0;
288                         if (NULL == fgets (line, sizeof (line), this->socket)) {
289                                 if (0 != errno) {
290                                         char errbuf[1024];
291                                         log_err ("collect: reading from socket (fd #%i) "
292                                                         "failed: %s", fileno (this->socket),
293                                                         sstrerror (errno, errbuf, sizeof (errbuf)));
294                                 }
295                                 break;
296                         }
297
298                         len = strlen (line);
299                         if (('\n' != line[len - 1]) && ('\r' != line[len - 1])) {
300                                 log_warn ("collect: line too long (> %zu characters): "
301                                                 "'%s' (truncated)", sizeof (line) - 1, line);
302
303                                 while (NULL != fgets (line, sizeof (line), this->socket))
304                                         if (('\n' == line[len - 1]) || ('\r' == line[len - 1]))
305                                                 break;
306                                 continue;
307                         }
308
309                         line[len - 1] = '\0';
310
311                         log_debug ("collect: line = '%s'", line);
312
313                         if (':' != line[1]) {
314                                 log_err ("collect: syntax error in line '%s'", line);
315                                 continue;
316                         }
317
318                         if ('e' == line[0]) { /* e:<type>:<bytes> */
319                                 char *ptr  = NULL;
320                                 char *type = strtok_r (line + 2, ":", &ptr);
321                                 char *tmp  = strtok_r (NULL, ":", &ptr);
322                                 int  bytes = 0;
323
324                                 if (NULL == tmp) {
325                                         log_err ("collect: syntax error in line '%s'", line);
326                                         continue;
327                                 }
328
329                                 bytes = atoi (tmp);
330
331                                 pthread_mutex_lock (&count_mutex);
332                                 type_list_incr (&list_count, type, 1);
333                                 pthread_mutex_unlock (&count_mutex);
334
335                                 if (bytes > 0) {
336                                         pthread_mutex_lock (&size_mutex);
337                                         type_list_incr (&list_size, type, bytes);
338                                         pthread_mutex_unlock (&size_mutex);
339                                 }
340                         }
341                         else if ('s' == line[0]) { /* s:<value> */
342                                 pthread_mutex_lock (&score_mutex);
343                                 score = (score * (double)score_count + atof (line + 2))
344                                                 / (double)(score_count + 1);
345                                 ++score_count;
346                                 pthread_mutex_unlock (&score_mutex);
347                         }
348                         else if ('c' == line[0]) { /* c:<type1>[,<type2>,...] */
349                                 char *ptr  = NULL;
350                                 char *type = strtok_r (line + 2, ",", &ptr);
351
352                                 do {
353                                         pthread_mutex_lock (&check_mutex);
354                                         type_list_incr (&list_check, type, 1);
355                                         pthread_mutex_unlock (&check_mutex);
356                                 } while (NULL != (type = strtok_r (NULL, ",", &ptr)));
357                         }
358                         else {
359                                 log_err ("collect: unknown type '%c'", line[0]);
360                         }
361                 } /* while (42) */
362
363                 log_debug ("Shutting down connection on fd #%i",
364                                 fileno (this->socket));
365
366                 fclose (connection->socket);
367                 free (connection);
368
369                 this->socket = NULL;
370
371                 pthread_mutex_lock (&available_mutex);
372                 ++available_collectors;
373                 pthread_mutex_unlock (&available_mutex);
374
375                 pthread_cond_signal (&collector_available);
376         } /* while (1) */
377
378         pthread_exit ((void *)0);
379         return ((void *) 0);
380 } /* static void *collect (void *) */
381
382 static void *open_connection (void __attribute__((unused)) *arg)
383 {
384         struct sockaddr_un addr;
385
386         char *path  = (NULL == sock_file) ? SOCK_PATH : sock_file;
387         char *group = (NULL == sock_group) ? COLLECTD_GRP_NAME : sock_group;
388
389         /* create UNIX socket */
390         errno = 0;
391         if (-1 == (connector_socket = socket (PF_UNIX, SOCK_STREAM, 0))) {
392                 char errbuf[1024];
393                 disabled = 1;
394                 log_err ("socket() failed: %s",
395                                 sstrerror (errno, errbuf, sizeof (errbuf)));
396                 pthread_exit ((void *)1);
397         }
398
399         addr.sun_family = AF_UNIX;
400         sstrncpy (addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));
401
402         errno = 0;
403         if (-1 == bind (connector_socket, (struct sockaddr *)&addr,
404                                 offsetof (struct sockaddr_un, sun_path)
405                                         + strlen(addr.sun_path))) {
406                 char errbuf[1024];
407                 disabled = 1;
408                 close (connector_socket);
409                 connector_socket = -1;
410                 log_err ("bind() failed: %s",
411                                 sstrerror (errno, errbuf, sizeof (errbuf)));
412                 pthread_exit ((void *)1);
413         }
414
415         errno = 0;
416         if (-1 == listen (connector_socket, 5)) {
417                 char errbuf[1024];
418                 disabled = 1;
419                 close (connector_socket);
420                 connector_socket = -1;
421                 log_err ("listen() failed: %s",
422                                 sstrerror (errno, errbuf, sizeof (errbuf)));
423                 pthread_exit ((void *)1);
424         }
425
426         {
427                 struct group sg;
428                 struct group *grp;
429                 char grbuf[2048];
430                 int status;
431
432                 grp = NULL;
433                 status = getgrnam_r (group, &sg, grbuf, sizeof (grbuf), &grp);
434                 if (status != 0)
435                 {
436                         char errbuf[1024];
437                         log_warn ("getgrnam_r (%s) failed: %s", group,
438                                         sstrerror (errno, errbuf, sizeof (errbuf)));
439                 }
440                 else if (grp == NULL)
441                 {
442                         log_warn ("No such group: `%s'", group);
443                 }
444                 else
445                 {
446                         status = chown (path, (uid_t) -1, grp->gr_gid);
447                         if (status != 0)
448                         {
449                                 char errbuf[1024];
450                                 log_warn ("chown (%s, -1, %i) failed: %s",
451                                                 path, (int) grp->gr_gid,
452                                                 sstrerror (errno, errbuf, sizeof (errbuf)));
453                         }
454                 }
455         }
456
457         errno = 0;
458         if (0 != chmod (path, sock_perms)) {
459                 char errbuf[1024];
460                 log_warn ("chmod() failed: %s",
461                                 sstrerror (errno, errbuf, sizeof (errbuf)));
462         }
463
464         { /* initialize collector threads */
465                 int i   = 0;
466                 int err = 0;
467
468                 pthread_attr_t ptattr;
469
470                 conns.head = NULL;
471                 conns.tail = NULL;
472
473                 pthread_attr_init (&ptattr);
474                 pthread_attr_setdetachstate (&ptattr, PTHREAD_CREATE_DETACHED);
475
476                 available_collectors = max_conns;
477
478                 collectors =
479                         (collector_t **)smalloc (max_conns * sizeof (collector_t *));
480
481                 for (i = 0; i < max_conns; ++i) {
482                         collectors[i] = (collector_t *)smalloc (sizeof (collector_t));
483                         collectors[i]->socket = NULL;
484
485                         if (0 != (err = plugin_thread_create (&collectors[i]->thread,
486                                                         &ptattr, collect, collectors[i]))) {
487                                 char errbuf[1024];
488                                 log_err ("pthread_create() failed: %s",
489                                                 sstrerror (errno, errbuf, sizeof (errbuf)));
490                                 collectors[i]->thread = (pthread_t) 0;
491                         }
492                 }
493
494                 pthread_attr_destroy (&ptattr);
495         }
496
497         while (1) {
498                 int remote = 0;
499
500                 conn_t *connection;
501
502                 pthread_mutex_lock (&available_mutex);
503
504                 while (0 == available_collectors) {
505                         pthread_cond_wait (&collector_available, &available_mutex);
506                 }
507
508                 --available_collectors;
509
510                 pthread_mutex_unlock (&available_mutex);
511
512                 while (42) {
513                         errno = 0;
514
515                         remote = accept (connector_socket, NULL, NULL);
516                         if (remote == -1) {
517                                 char errbuf[1024];
518
519                                 if (errno == EINTR)
520                                         continue;
521
522                                 disabled = 1;
523                                 close (connector_socket);
524                                 connector_socket = -1;
525                                 log_err ("accept() failed: %s",
526                                                  sstrerror (errno, errbuf, sizeof (errbuf)));
527                                 pthread_exit ((void *)1);
528                         }
529
530                         /* access() succeeded. */
531                         break;
532                 }
533
534                 connection = malloc (sizeof (*connection));
535                 if (connection == NULL)
536                 {
537                         close (remote);
538                         continue;
539                 }
540                 memset (connection, 0, sizeof (*connection));
541
542                 connection->socket = fdopen (remote, "r");
543                 connection->next   = NULL;
544
545                 if (NULL == connection->socket) {
546                         close (remote);
547                         sfree (connection);
548                         continue;
549                 }
550
551                 pthread_mutex_lock (&conns_mutex);
552
553                 if (NULL == conns.head) {
554                         conns.head = connection;
555                         conns.tail = connection;
556                 }
557                 else {
558                         conns.tail->next = connection;
559                         conns.tail = conns.tail->next;
560                 }
561
562                 pthread_mutex_unlock (&conns_mutex);
563
564                 pthread_cond_signal (&conn_available);
565         }
566
567         pthread_exit ((void *) 0);
568         return ((void *) 0);
569 } /* static void *open_connection (void *) */
570
571 static int email_init (void)
572 {
573         int err = 0;
574
575         if (0 != (err = plugin_thread_create (&connector, NULL,
576                                 open_connection, NULL))) {
577                 char errbuf[1024];
578                 disabled = 1;
579                 log_err ("pthread_create() failed: %s",
580                                 sstrerror (errno, errbuf, sizeof (errbuf)));
581                 return (-1);
582         }
583
584         return (0);
585 } /* int email_init */
586
587 static void type_list_free (type_list_t *t)
588 {
589         type_t *this;
590
591         this = t->head;
592         while (this != NULL)
593         {
594                 type_t *next = this->next;
595
596                 sfree (this->name);
597                 sfree (this);
598
599                 this = next;
600         }
601
602         t->head = NULL;
603         t->tail = NULL;
604 }
605
606 static int email_shutdown (void)
607 {
608         int i = 0;
609
610         if (connector != ((pthread_t) 0)) {
611                 pthread_kill (connector, SIGTERM);
612                 connector = (pthread_t) 0;
613         }
614
615         if (connector_socket >= 0) {
616                 close (connector_socket);
617                 connector_socket = -1;
618         }
619
620         /* don't allow any more connections to be processed */
621         pthread_mutex_lock (&conns_mutex);
622
623         available_collectors = 0;
624
625         if (collectors != NULL) {
626                 for (i = 0; i < max_conns; ++i) {
627                         if (collectors[i] == NULL)
628                                 continue;
629
630                         if (collectors[i]->thread != ((pthread_t) 0)) {
631                                 pthread_kill (collectors[i]->thread, SIGTERM);
632                                 collectors[i]->thread = (pthread_t) 0;
633                         }
634
635                         if (collectors[i]->socket != NULL) {
636                                 fclose (collectors[i]->socket);
637                                 collectors[i]->socket = NULL;
638                         }
639
640                         sfree (collectors[i]);
641                 }
642                 sfree (collectors);
643         } /* if (collectors != NULL) */
644
645         pthread_mutex_unlock (&conns_mutex);
646
647         type_list_free (&list_count);
648         type_list_free (&list_count_copy);
649         type_list_free (&list_size);
650         type_list_free (&list_size_copy);
651         type_list_free (&list_check);
652         type_list_free (&list_check_copy);
653
654         unlink ((NULL == sock_file) ? SOCK_PATH : sock_file);
655
656         sfree (sock_file);
657         sfree (sock_group);
658         return (0);
659 } /* static void email_shutdown (void) */
660
661 static void email_submit (const char *type, const char *type_instance, gauge_t value)
662 {
663         value_t values[1];
664         value_list_t vl = VALUE_LIST_INIT;
665
666         values[0].gauge = value;
667
668         vl.values = values;
669         vl.values_len = 1;
670         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
671         sstrncpy (vl.plugin, "email", sizeof (vl.plugin));
672         sstrncpy (vl.type, type, sizeof (vl.type));
673         sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
674
675         plugin_dispatch_values (&vl);
676 } /* void email_submit */
677
678 /* Copy list l1 to list l2. l2 may partly exist already, but it is assumed
679  * that neither the order nor the name of any element of either list is
680  * changed and no elements are deleted. The values of l1 are reset to zero
681  * after they have been copied to l2. */
682 static void copy_type_list (type_list_t *l1, type_list_t *l2)
683 {
684         type_t *ptr1;
685         type_t *ptr2;
686
687         type_t *last = NULL;
688
689         for (ptr1 = l1->head, ptr2 = l2->head; NULL != ptr1;
690                         ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) {
691                 if (NULL == ptr2) {
692                         ptr2 = (type_t *)smalloc (sizeof (type_t));
693                         ptr2->name = NULL;
694                         ptr2->next = NULL;
695
696                         if (NULL == last) {
697                                 l2->head = ptr2;
698                         }
699                         else {
700                                 last->next = ptr2;
701                         }
702
703                         l2->tail = ptr2;
704                 }
705
706                 if (NULL == ptr2->name) {
707                         ptr2->name = sstrdup (ptr1->name);
708                 }
709
710                 ptr2->value = ptr1->value;
711                 ptr1->value = 0;
712         }
713         return;
714 }
715
716 static int email_read (void)
717 {
718         type_t *ptr;
719
720         double score_old;
721         int score_count_old;
722
723         if (disabled)
724                 return (-1);
725
726         /* email count */
727         pthread_mutex_lock (&count_mutex);
728
729         copy_type_list (&list_count, &list_count_copy);
730
731         pthread_mutex_unlock (&count_mutex);
732
733         for (ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) {
734                 email_submit ("email_count", ptr->name, ptr->value);
735         }
736
737         /* email size */
738         pthread_mutex_lock (&size_mutex);
739
740         copy_type_list (&list_size, &list_size_copy);
741
742         pthread_mutex_unlock (&size_mutex);
743
744         for (ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) {
745                 email_submit ("email_size", ptr->name, ptr->value);
746         }
747
748         /* spam score */
749         pthread_mutex_lock (&score_mutex);
750
751         score_old = score;
752         score_count_old = score_count;
753         score = 0.0;
754         score_count = 0;
755
756         pthread_mutex_unlock (&score_mutex);
757
758         if (score_count_old > 0)
759                 email_submit ("spam_score", "", score_old);
760
761         /* spam checks */
762         pthread_mutex_lock (&check_mutex);
763
764         copy_type_list (&list_check, &list_check_copy);
765
766         pthread_mutex_unlock (&check_mutex);
767
768         for (ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
769                 email_submit ("spam_check", ptr->name, ptr->value);
770
771         return (0);
772 } /* int email_read */
773
774 void module_register (void)
775 {
776         plugin_register_config ("email", email_config, config_keys, config_keys_num);
777         plugin_register_init ("email", email_init);
778         plugin_register_read ("email", email_read);
779         plugin_register_shutdown ("email", email_shutdown);
780 } /* void module_register */
781
782 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */