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.
108 /* Unblock the other side */
113 * this thread operates the select() etc. via libevent.
117 void *client_event_thread(void *arg) {
118 struct CitContext libevent_client_CC;
119 event_base = event_init();
121 base = event_base_new();
123 return NULL; /*XXXerr*/
125 citthread_mutex_init(&EventQueueMutex, NULL);
126 CtdlFillSystemContext(&libevent_client_CC, "LibEvent Thread");
127 // citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
128 CtdlLogPrintf(CTDL_DEBUG, "client_event_thread() initializing\n");
130 if (pipe(event_add_pipe) != 0) {
131 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for libevent queueing: %s\n", strerror(errno));
135 event_set(&queue_add_event,
138 QueueEventAddCallback,
141 event_add(&queue_add_event, NULL);
145 CtdlClearSystemContext();
146 event_base_free(event_base);
147 citthread_mutex_destroy(&EventQueueMutex);
153 CTDL_MODULE_INIT(event_client)
155 #ifdef EXPERIMENTAL_SMTP_EVENT_CLIENT
158 CtdlThreadCreate("Client event", CTDLTHREAD_BIGSTACK, client_event_thread, NULL);
159 QueueEvents = NewHashList(1, Flathash);
160 /// todo register shutdown callback.