2 * This module is an SMTP and ESMTP implementation for the Citadel system.
3 * It is compliant with all of the following:
5 * RFC 821 - Simple Mail Transfer Protocol
6 * RFC 876 - Survey of SMTP Implementations
7 * RFC 1047 - Duplicate messages and SMTP
8 * RFC 1652 - 8 bit MIME
9 * RFC 1869 - Extended Simple Mail Transfer Protocol
10 * RFC 1870 - SMTP Service Extension for Message Size Declaration
11 * RFC 2033 - Local Mail Transfer Protocol
12 * RFC 2197 - SMTP Service Extension for Command Pipelining
13 * RFC 2476 - Message Submission
14 * RFC 2487 - SMTP Service Extension for Secure SMTP over TLS
15 * RFC 2554 - SMTP Service Extension for Authentication
16 * RFC 2821 - Simple Mail Transfer Protocol
17 * RFC 2822 - Internet Message Format
18 * RFC 2920 - SMTP Service Extension for Command Pipelining
20 * The VRFY and EXPN commands have been removed from this implementation
21 * because nobody uses these commands anymore, except for spammers.
23 * Copyright (c) 1998-2009 by the citadel.org team
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
49 #include <sys/types.h>
52 #if TIME_WITH_SYS_TIME
53 # include <sys/time.h>
57 # include <sys/time.h>
66 #include <sys/socket.h>
67 #include <netinet/in.h>
68 #include <arpa/inet.h>
69 #include <libcitadel.h>
72 #include "citserver.h"
75 #include "ctdl_module.h"
77 #ifdef EXPERIMENTAL_SMTP_EVENT_CLIENT
79 #include "event_client.h"
81 int event_add_pipe[2];
83 citthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
84 void *QueueEventAddPtr = NULL;
85 EventContextAttach EventContextAttachPtr;
87 HashList *QueueEvents = NULL;
89 static struct event_base *event_base;
90 struct event queue_add_event;
92 static void QueueEventAddCallback(int fd, short event, void *ctx)
96 /* get the control command... */
100 EventContextAttachPtr(QueueEventAddPtr);
101 /// TODO: add it to QueueEvents
104 event_del(&queue_add_event);
105 close(event_add_pipe[0]);
106 /// TODO; flush QueueEvents fd's and delete it.
107 event_base_loopexit(event_base, NULL);
109 /* Unblock the other side */
114 * this thread operates the select() etc. via libevent.
118 void *client_event_thread(void *arg) {
119 struct CitContext libevent_client_CC;
120 event_base = event_init();
122 base = event_base_new();
124 return NULL; /*XXXerr*/
126 citthread_mutex_init(&EventQueueMutex, NULL);
127 CtdlFillSystemContext(&libevent_client_CC, "LibEvent Thread");
128 // citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
129 CtdlLogPrintf(CTDL_DEBUG, "client_event_thread() initializing\n");
131 if (pipe(event_add_pipe) != 0) {
132 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for libevent queueing: %s\n", strerror(errno));
136 event_set(&queue_add_event,
139 QueueEventAddCallback,
142 event_add(&queue_add_event, NULL);
146 CtdlClearSystemContext();
147 event_base_free(event_base);
148 citthread_mutex_destroy(&EventQueueMutex);
154 CTDL_MODULE_INIT(event_client)
156 #ifdef EXPERIMENTAL_SMTP_EVENT_CLIENT
159 CtdlThreadCreate("Client event", CTDLTHREAD_BIGSTACK, client_event_thread, NULL);
160 QueueEvents = NewHash(1, Flathash);
161 /// todo register shutdown callback.