diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Makefile.am | 9 | ||||
-rw-r--r-- | acl.c | 14 | ||||
-rw-r--r-- | acl.h | 13 | ||||
-rw-r--r-- | auth.h | 6 | ||||
-rw-r--r-- | auth/authsql.c | 7 | ||||
-rw-r--r-- | check_dbmail.h | 181 | ||||
-rw-r--r-- | check_dbmail_common.c | 18 | ||||
-rw-r--r-- | check_dbmail_deliver.c | 26 | ||||
-rw-r--r-- | check_dbmail_imapd.c | 265 | ||||
-rw-r--r-- | check_dbmail_message.c | 123 | ||||
-rw-r--r-- | check_dbmail_server.c | 14 | ||||
-rw-r--r-- | check_dbmail_user.c | 12 | ||||
-rw-r--r-- | check_dbmail_util.c | 11 | ||||
-rw-r--r-- | config.c | 13 | ||||
-rw-r--r-- | db.c | 131 | ||||
-rw-r--r-- | db.h | 10 | ||||
-rw-r--r-- | dbmail-imapsession.c | 1235 | ||||
-rw-r--r-- | dbmail-imapsession.h | 8 | ||||
-rw-r--r-- | dbmail-message.c | 119 | ||||
-rw-r--r-- | dbmail-message.h | 18 | ||||
-rw-r--r-- | dbmail-user.c | 24 | ||||
-rw-r--r-- | dbmail-user.h | 8 | ||||
-rw-r--r-- | dbmail.h | 155 | ||||
-rw-r--r-- | dbmailtypes.h | 146 | ||||
-rw-r--r-- | dbmd5.c | 12 | ||||
-rw-r--r-- | dbmd5.h | 4 | ||||
-rw-r--r-- | dbmsgbuf.c | 137 | ||||
-rw-r--r-- | dbmsgbuf.h | 14 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debug.c | 11 | ||||
-rw-r--r-- | debug.h | 33 | ||||
-rw-r--r-- | dm_cidr.c | 10 | ||||
-rw-r--r-- | dm_cidr.h | 4 | ||||
-rw-r--r-- | dm_getopt.c | 6 | ||||
-rw-r--r-- | dm_search.c | 92 | ||||
-rw-r--r-- | dm_search.h | 6 | ||||
-rw-r--r-- | dsn.c | 8 | ||||
-rw-r--r-- | dsn.h | 2 | ||||
-rw-r--r-- | forward.c | 13 | ||||
-rw-r--r-- | forward.h | 4 | ||||
-rw-r--r-- | imap4.c | 18 | ||||
-rw-r--r-- | imap4.h | 6 | ||||
-rw-r--r-- | imapcommands.c | 31 | ||||
-rw-r--r-- | imapcommands.h | 6 | ||||
-rw-r--r-- | imapd.c | 17 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | list.c | 11 | ||||
-rw-r--r-- | list.h | 8 | ||||
-rw-r--r-- | lmtp.c | 27 | ||||
-rw-r--r-- | lmtp.h | 25 | ||||
-rw-r--r-- | lmtpd.c | 18 | ||||
-rw-r--r-- | main.c | 20 | ||||
-rw-r--r-- | main.h | 34 | ||||
-rw-r--r-- | maintenance.c | 24 | ||||
-rw-r--r-- | md5.c | 11 | ||||
-rw-r--r-- | md5.h | 4 | ||||
-rw-r--r-- | memblock.c | 11 | ||||
-rw-r--r-- | memblock.h | 4 | ||||
-rw-r--r-- | mime.c | 90 | ||||
-rw-r--r-- | mime.h | 13 | ||||
-rw-r--r-- | misc.c | 20 | ||||
-rw-r--r-- | misc.h | 16 | ||||
-rw-r--r-- | mysql/dbmysql.c | 9 | ||||
-rw-r--r-- | pidfile.c | 9 | ||||
-rw-r--r-- | pidfile.h | 2 | ||||
-rw-r--r-- | pipe.c | 29 | ||||
-rw-r--r-- | pipe.h | 7 | ||||
-rw-r--r-- | pool.c | 19 | ||||
-rw-r--r-- | pool.h | 9 | ||||
-rw-r--r-- | pop3.c | 10 | ||||
-rw-r--r-- | pop3.h | 24 | ||||
-rw-r--r-- | pop3d.c | 20 | ||||
-rw-r--r-- | python/lib/dbmail.py | 49 | ||||
-rw-r--r-- | quota.c | 11 | ||||
-rw-r--r-- | quota.h | 5 | ||||
-rw-r--r-- | rfcmsg.c | 716 | ||||
-rw-r--r-- | rfcmsg.h | 6 | ||||
-rw-r--r-- | server.c | 28 | ||||
-rw-r--r-- | server.h | 26 | ||||
-rw-r--r-- | serverchild.c | 26 | ||||
-rw-r--r-- | serverchild.h | 8 | ||||
-rw-r--r-- | sievecmd.c | 24 | ||||
-rw-r--r-- | sievecmd.h | 11 | ||||
-rw-r--r-- | sort.h | 22 | ||||
-rw-r--r-- | sort/sortsieve.c | 23 | ||||
-rw-r--r-- | sort/sortsieve.h | 6 | ||||
-rw-r--r-- | sql/mysql/create_tables.mysql | 2 | ||||
-rw-r--r-- | sql/mysql/create_tables_innoDB.mysql | 2 | ||||
-rw-r--r-- | tags | 357 | ||||
-rwxr-xr-x | test-scripts/testimap.py | 74 | ||||
-rw-r--r-- | timsieve.c | 11 | ||||
-rw-r--r-- | timsieve.h | 25 | ||||
-rw-r--r-- | timsieved.c | 20 | ||||
-rw-r--r-- | user.c | 25 |
96 files changed, 1588 insertions, 3379 deletions
@@ -1,3 +1,9 @@ +2005-09-10 Paul J Stevens <paul@nfg.nl> + + * ChangeLog, check_dbmail_imapd.c, check_dbmail_message.c, + dbmail-imapsession.c, mime.c, test-scripts/testimap.py: + more cleanups in the mime code + 2005-09-09 Paul J Stevens <paul@nfg.nl> * check_dbmail_imapd.c, check_dbmail_message.c, db.c, dbmail-imapsession.c, diff --git a/Makefile.am b/Makefile.am index c46add3c..2f41b2ae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,7 +62,7 @@ dbmail_smtp_LDADD = libdbmail.la dbmail_pop3d_SOURCES = pop3.c pop3d.c dbmail_pop3d_LDADD = libdbmail.la -dbmail_imapd_SOURCES = quota.c imap4.c imaputil.c imapcommands.c memblock.c rfcmsg.c imapd.c dm_search.c dbmsgbuf.c acl.c dbmail-imapsession.c +dbmail_imapd_SOURCES = quota.c imap4.c dm_imaputil.c imapcommands.c memblock.c rfcmsg.c imapd.c dm_search.c dbmsgbuf.c acl.c dbmail-imapsession.c dbmail_imapd_LDADD = libdbmail.la dbmail_util_SOURCES = maintenance.c @@ -93,6 +93,7 @@ TESTS=check_dbmail_common \ check_dbmail_deliver \ check_dbmail_imapd \ check_dbmail_message \ + check_dbmail_mailbox \ check_dbmail_user \ check_dbmail_util @@ -122,7 +123,11 @@ check_dbmail_message_SOURCES=check_dbmail_message.c check_dbmail_message_LDADD=@CHECK_LIBS@ libdbmail.la check_dbmail_message_INCLUDES=@CHECK_CFLAGS@ -check_dbmail_imapd_SOURCES=quota.c imap4.c imaputil.c imapcommands.c memblock.c rfcmsg.c dm_search.c dbmsgbuf.c acl.c dbmail-imapsession.c check_dbmail_imapd.c +check_dbmail_mailbox_SOURCES=check_dbmail_mailbox.c +check_dbmail_mailbox_LDADD=@CHECK_LIBS@ libdbmail.la +check_dbmail_mailbox_INCLUDES=@CHECK_CFLAGS@ + +check_dbmail_imapd_SOURCES=quota.c imap4.c dm_imaputil.c imapcommands.c memblock.c rfcmsg.c dm_search.c dbmsgbuf.c acl.c dbmail-imapsession.c check_dbmail_imapd.c check_dbmail_imapd_LDADD=@CHECK_LIBS@ libdbmail.la check_dbmail_imapd_INCLUDES=@CHECK_CFLAGS@ @@ -16,18 +16,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef NULL -#define NULL 0 -#endif - -#include "acl.h" -#include "auth.h" -#include "db.h" -#include "debug.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> + +#include "dbmail.h" #define NR_ACL_FLAGS 9 @@ -31,19 +31,6 @@ /** * different rights a user can have on a mailbox */ -typedef enum { - ACL_RIGHT_LOOKUP, - ACL_RIGHT_READ, - ACL_RIGHT_SEEN, - ACL_RIGHT_WRITE, - ACL_RIGHT_INSERT, - ACL_RIGHT_POST, - ACL_RIGHT_CREATE, - ACL_RIGHT_DELETE, - ACL_RIGHT_ADMINISTER, - ACL_RIGHT_NONE -} ACLRight_t; - #include "dbmailtypes.h" @@ -29,11 +29,7 @@ #ifndef _DBMAIL_AUTH_H #define _DBMAIL_AUTH_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmailtypes.h" +#include "dbmail.h" #define MAX_CHECKS_DEPTH 1000 #define DBMAIL_USE_SAME_CONNECTION 0 diff --git a/auth/authsql.c b/auth/authsql.c index d5bb8b6d..4678cf69 100644 --- a/auth/authsql.c +++ b/auth/authsql.c @@ -28,13 +28,7 @@ #include "config.h" #endif -#include "auth.h" -#include "db.h" -#include "list.h" -#include "debug.h" -#include "dbmd5.h" #include "dbmail.h" -#include "misc.h" #include <assert.h> #include <stdlib.h> @@ -909,7 +903,6 @@ int auth_removealias_ext(const char *alias, const char *deliver_to) return 0; } - GList * auth_get_user_aliases(u64_t user_idnr) { int i, n; diff --git a/check_dbmail.h b/check_dbmail.h index 70aec7ce..e1123136 100644 --- a/check_dbmail.h +++ b/check_dbmail.h @@ -3,8 +3,22 @@ char *configFile = "/etc/dbmail/dbmail-test.conf"; + /* simple testmessages. */ -char *raw_message = "From: \"Brother from another planet\" <vol@inter7.com>\n" + +char *rfc822 = "From nobody Wed Sep 14 16:47:48 2005\n" + "Content-Type: text/plain; charset=\"us-ascii\"\n" + "MIME-Version: 1.0\n" + "Content-Transfer-Encoding: 7bit\n" + "To: testuser@foo.org\n" + "From: somewher@foo.org\n" + "Subject: dbmail test message\n" + "\n" + "\n" + " this is a test message\n" + "\n"; + +char *multipart_message = "From: \"Brother from another planet\" <vol@inter7.com>\n" "To: \"Brother from another planet\" <vol@inter7.com>\n" "Reply-to: \"Brother from another planet\" <vol@inter7.com>\n" "Cc: \"Brother from another planet\" <vol@inter7.com>,\n" @@ -47,7 +61,168 @@ char *raw_message = "From: \"Brother from another planet\" <vol@inter7.com>\n" "dXJpdHkuaXM+ICAgICAgICAgICAgICAgICAgIHwiDQplY2hvICJ8IE1pY2hh\n" "--boundary--\n"; -/* raw_lmtp_data is equal to raw_message, except for the line-endings +char *outlook_multipart = "From: someone@somewhere.nl\n" + "To: \"Baby's geboren in april 1999...\" <aprilbabies@lists.nfg.nl>\n" + "Subject: RE: [Aprilbabies] hallo meisjes (O:\n" + "Date: Sat, 20 Aug 2005 11:19:59 +0200\n" + "Message-ID: <IFEIKJKAMPLPGJIEIMEEEEMNEBAA@somewhere.nl>\n" + "In-Reply-To: <00bc01c5a4a4$5045f140$9a00000a@ajzw5e08blxvtd>\n" + "Precedence: list\n" + "MIME-Version: 1.0\n" + "Content-Type: multipart/mixed;\n" + " boundary=\"===============0257742399==\"\n" + "\n" + "\n" + "This is a multi-part message in MIME format.\n" + "\n" + "--===============0257742399==\n" + "Content-Type: multipart/alternative;\n" + " boundary=\"----=_NextPart_000_0009_01C5A579.19D2FA10\"\n" + "\n" + "This is a multi-part message in MIME format.\n" + "\n" + "------=_NextPart_000_0009_01C5A579.19D2FA10\n" + "Content-Type: text/plain;\n" + " charset=\"iso-8859-1\"\n" + "Content-Transfer-Encoding: 7bit\n" + "\n" + "Haidihi,\n" + "\n" + "\n" + "\n" + "-----Oorspronkelijk bericht-----\n" + "Van: somelist-bounces@lists.nfg.nl\n" + "[mailto:somelist-bounces@lists.nfg.nl]Namens o0o Monique o0o\n" + "Verzonden: vrijdag 19 augustus 2005 10:42\n" + "Aan: somelist@nfg.nl\n" + "Onderwerp: [Somelist] hallo meisjes (O:\n" + "\n" + "Liefs en tot snel ..\n" + "\n" + "------=_NextPart_000_0009_01C5A579.19D2FA10\n" + "Content-Type: text/html;\n" + " charset=\"iso-8859-1\"\n" + "Content-Transfer-Encoding: quoted-printable\n" + "\n" + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n" + "<html xmlns:v=3D\"urn:schemas-microsoft-com:vml\" =\n" + "xmlns:o=3D\"urn:schemas-microsoft-com:office:office\" =\n" + "xmlns:w=3D\"urn:schemas-microsoft-com:office:word\" =\n" + "xmlns=3D\"http://www.w3.org/TR/REC-html40\">\n" + "\n" + "<head>\n" + "<meta http-equiv=3DContent-Type content=3D\"text/html; =\n" + "charset=3Diso-8859-1\">\n" + "<meta name=3DProgId content=3DWord.Document>\n" + "<meta name=3DGenerator content=3D\"Microsoft Word 9\">\n" + "<meta name=3DOriginator content=3D\"Microsoft Word 9\">\n" + "<link rel=3DFile-List href=3D\"cid:filelist.xml@01C5A578.FDF0C340\">\n" + "<!--[if gte mso 9]><xml>\n" + " <o:OfficeDocumentSettings>\n" + " <o:DoNotRelyOnCSS/>\n" + " </o:OfficeDocumentSettings>\n" + "</xml><![endif]--><!--[if gte mso 9]><xml>\n" + " <w:WordDocument>\n" + " <w:Zoom>0</w:Zoom>\n" + " <w:DocumentKind>DocumentEmail</w:DocumentKind>\n" + " <w:HyphenationZone>21</w:HyphenationZone>\n" + " <w:EnvelopeVis/>\n" + " </w:WordDocument>\n" + "</xml><![endif]-->\n" + "<style>\n" + "<!--\n" + " /* Font Definitions */\n" + "@font-face\n" + " {font-family:Tahoma;\n" + " panose-1:2 11 6 4 3 5 4 4 2 4;\n" + " mso-font-charset:0;\n" + " mso-generic-font-family:swiss;\n" + " mso-font-pitch:variable;\n" + " mso-font-signature:1627421319 -2147483648 8 0 66047 0;}\n" + "@font-face\n" + " {font-family:\"Comic Sans MS\";\n" + " panose-1:3 15 7 2 3 3 2 2 2 4;\n" + " mso-font-charset:0;\n" + " mso-generic-font-family:script;\n" + " mso-font-pitch:variable;\n" + " mso-font-signature:647 0 0 0 159 0;}\n" + " /* Style Definitions */\n" + "p.MsoNormal, li.MsoNormal, div.MsoNormal\n" + " {mso-style-parent:\"\";\n" + " margin:0cm;\n" + " margin-bottom:.0001pt;\n" + " mso-pagination:widow-orphan;\n" + " font-size:12.0pt;\n" + " font-family:\"Times New Roman\";\n" + " mso-fareast-font-family:\"Times New Roman\";}\n" + "p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig\n" + " {margin:0cm;\n" + " margin-bottom:.0001pt;\n" + " mso-pagination:widow-orphan;\n" + " font-size:12.0pt;\n" + " font-family:\"Times New Roman\";\n" + " mso-fareast-font-family:\"Times New Roman\";}\n" + "span.EmailStijl15\n" + " {mso-style-type:personal-reply;\n" + " mso-ansi-font-size:10.0pt;\n" + " mso-ascii-font-family:Arial;\n" + " mso-hansi-font-family:Arial;\n" + " mso-bidi-font-family:Arial;\n" + " color:navy;}\n" + "@page Section1\n" + " {size:595.3pt 841.9pt;\n" + " margin:70.85pt 70.85pt 70.85pt 70.85pt;\n" + " mso-header-margin:35.4pt;\n" + " mso-footer-margin:35.4pt;\n" + " mso-paper-source:0;}\n" + "div.Section1\n" + " {page:Section1;}\n" + "-->\n" + "</style>\n" + "<!--[if gte mso 9]><xml>\n" + " <o:shapedefaults v:ext=3D\"edit\" spidmax=3D\"1027\"/>\n" + "</xml><![endif]--><!--[if gte mso 9]><xml>\n" + " <o:shapelayout v:ext=3D\"edit\">\n" + " <o:idmap v:ext=3D\"edit\" data=3D\"1\"/>\n" + " </o:shapelayout></xml><![endif]-->\n" + "</head>\n" + "\n" + "<body bgcolor=3Dwhite lang=3DNL style=3D'tab-interval:35.4pt'>\n" + "\n" + "<div class=3DSection1>\n" + "\n" + "<p class=3DMsoNormal><span class=3DEmailStijl15><font size=3D3 =\n" + "color=3Dnavy\n" + "face=3D\"Comic Sans MS\"><span =\n" + "style=3D'font-size:12.0pt;mso-ansi-font-size:12.0pt;\n" + "font-family:\"Comic Sans MS\"'>Haidihi, =\n" + "<o:p></o:p></span></font></span></p>\n" + "\n" + "</div>\n" + "\n" + "</body>\n" + "\n" + "</html>\n" + "\n" + "------=_NextPart_000_0009_01C5A579.19D2FA10--\n" + "\n" + "\n" + "\n" + "\n" + "--===============0257742399==\n" + "Content-Type: text/plain; charset=\"iso-8859-1\"\n" + "MIME-Version: 1.0\n" + "Content-Transfer-Encoding: quoted-printable\n" + "Content-Disposition: inline\n" + "\n" + "'Jaahaa, want het is zo, en anders heb ik gelijk'\n" + "Het gelijk van een vijfjarige.\n" + "--===============0257742399==--\n" + "\n" + "\n" + "\n"; + +/* raw_lmtp_data is equal to multipart_message, except for the line-endings * and the termination dot. */ char *raw_lmtp_data = "From: \"Brother from another planet\" <vol@inter7.com>\r\n" @@ -94,7 +269,7 @@ char *raw_lmtp_data = "From: \"Brother from another planet\" <vol@inter7.com>\r\ "--boundary--\r\n" ".\r\n"; -char *raw_message_part = "Content-Type: text/plain;\n" +char *multipart_message_part = "Content-Type: text/plain;\n" " name=\"mime_alternative\"\n" "Content-Transfer-Encoding: 7bit\n" "Content-Disposition: inline;\n" diff --git a/check_dbmail_common.c b/check_dbmail_common.c index 39f165d7..e969dbe6 100644 --- a/check_dbmail_common.c +++ b/check_dbmail_common.c @@ -31,21 +31,7 @@ * */ -#include <stdlib.h> #include <check.h> -#include <gmime/gmime.h> -#include <stdio.h> -#include <string.h> - -#include "dbmail-imapsession.h" -#include "dbmail-message.h" -#include "mime.h" -#include "rfcmsg.h" -#include "dbmsgbuf.h" -#include "imaputil.h" -#include "config.h" -#include "pipe.h" - #include "check_dbmail.h" extern char *configFile; @@ -56,8 +42,8 @@ extern char *msgbuf_buf; extern u64_t msgbuf_idx; extern u64_t msgbuf_buflen; -extern char *raw_message; -extern char *raw_message_part; +extern char *multipart_message; +extern char *multipart_message_part; extern char *raw_lmtp_data; /* diff --git a/check_dbmail_deliver.c b/check_dbmail_deliver.c index 6953abf3..6f192852 100644 --- a/check_dbmail_deliver.c +++ b/check_dbmail_deliver.c @@ -31,26 +31,10 @@ * */ -#include <stdlib.h> #include <check.h> -#include <stdio.h> -#include <string.h> -#include <check.h> - -#include "dbmail.h" -#include "debug.h" -#include "db.h" -#include "auth.h" -#include "misc.h" -#include "dsn.h" -#include "dbmail-message.h" -#include "mime.h" -#include "pipe.h" -#include <gmime/gmime.h> - #include "check_dbmail.h" -extern char * raw_message; +extern char * multipart_message; extern char * configFile; extern db_param_t _db_params; @@ -107,14 +91,13 @@ void teardown(void) START_TEST(test_insert_messages) { int result; - char *header; struct DbmailMessage *message; struct dm_list dsnusers, headerfields, returnpath; GString *tmp; deliver_to_user_t dsnuser; message = dbmail_message_new(); - tmp = g_string_new(raw_message); + tmp = g_string_new(multipart_message); message = dbmail_message_init_with_string(message,tmp); dm_list_init(&dsnusers); @@ -125,10 +108,7 @@ START_TEST(test_insert_messages) dsnuser.address = "testuser1"; dm_list_nodeadd(&dsnusers, &dsnuser, sizeof(deliver_to_user_t)); - header = dbmail_message_hdrs_to_string(message, FALSE); - mime_fetch_headers(header, &headerfields); - g_free(header); - + mime_fetch_headers(message, &headerfields); result = insert_messages(message, &headerfields, &dsnusers, &returnpath); fail_unless(result==0,"insert_messages failed"); diff --git a/check_dbmail_imapd.c b/check_dbmail_imapd.c index 5b8ecb43..991ef14a 100644 --- a/check_dbmail_imapd.c +++ b/check_dbmail_imapd.c @@ -31,20 +31,7 @@ * */ -#include <stdlib.h> #include <check.h> -#include <gmime/gmime.h> -#include <stdio.h> -#include <string.h> - -#include "dbmail-imapsession.h" -#include "dbmail-message.h" -#include "mime.h" -#include "rfcmsg.h" -#include "dbmsgbuf.h" -#include "imaputil.h" -#include "misc.h" - #include "check_dbmail.h" extern char *configFile; @@ -57,8 +44,8 @@ extern char *msgbuf_buf; extern u64_t msgbuf_idx; extern u64_t msgbuf_buflen; -extern char *raw_message; -extern char *raw_message_part; +extern char *multipart_message; +extern char *multipart_message_part; extern char *raw_lmtp_data; void print_mimelist(struct dm_list *mimelist) @@ -77,18 +64,34 @@ void print_mimelist(struct dm_list *mimelist) * the test fixtures * */ - + +void init_testuser1(void) +{ + u64_t user_idnr; + if (! (auth_user_exists("testuser1",&user_idnr))) + auth_adduser("testuser1","test", "md5", 101, 1024000, &user_idnr); +} + void setup(void) { configure_debug(5,1,0); + config_read(configFile); + GetDBParams(&_db_params); + db_connect(); + auth_connect(); g_mime_init(0); + init_testuser1(); } void teardown(void) { + auth_disconnect(); + db_disconnect(); + config_free(); g_mime_shutdown(); } + START_TEST(test_g_list_join) { GString *result; @@ -101,19 +104,46 @@ START_TEST(test_g_list_join) fail_unless(strcmp(result->str,"NIL NIL (NIL NIL) (NIL NIL)")==0,"g_list_join failed"); g_string_free(result,TRUE); + l = NULL; + l = g_list_append(l, "NIL"); + result = g_list_join(l," "); + fail_unless(strcmp(result->str,"NIL")==0,"g_list_join failed"); + g_string_free(result,TRUE); + } END_TEST START_TEST(test_dbmail_imap_plist_as_string) { char *result; - GList *l = NULL; + GList *l; + + l = NULL; l = g_list_append(l, "NIL"); l = g_list_append(l, "NIL"); + result = dbmail_imap_plist_as_string(l); + fail_unless(strcmp(result,"(NIL NIL)")==0,"plist construction failed"); + + //g_list_foreach(l,(GFunc)g_free,NULL); + g_free(result); + + l = NULL; + l = g_list_append(l, "(NIL NIL)"); + result = dbmail_imap_plist_as_string(l); + fail_unless(strcmp(result,"(NIL NIL)")==0,"plist construction failed"); + + //g_list_foreach(l,(GFunc)g_free,NULL); + g_free(result); + + l = g_list_append(NULL, "NIL"); + l = g_list_append(l, "NIL"); l = g_list_append(l, "(NIL NIL)"); l = g_list_append(l, "(NIL NIL)"); result = dbmail_imap_plist_as_string(l); fail_unless(strcmp(result,"(NIL NIL (NIL NIL) (NIL NIL))")==0,"plist construction failed"); + + //g_list_foreach(l,(GFunc)g_free,NULL); + g_free(result); } END_TEST @@ -174,24 +204,35 @@ START_TEST(test_mime_readheader) int res; u64_t blkidx=0, headersize=0; struct dm_list mimelist; + struct DbmailMessage *m, *p; + + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m,g_string_new(multipart_message)); dm_list_init(&mimelist); - res = mime_readheader(raw_message,&blkidx,&mimelist,&headersize); - fail_unless(res==12, "number of newlines incorrect"); - fail_unless(blkidx==484, "blkidx incorrect"); - fail_unless(headersize==blkidx+res, "headersize incorrect"); - fail_unless(mimelist.total_nodes==10, "number of message-headers incorrect"); + res = mime_readheader(m,&blkidx,&mimelist,&headersize); + fail_unless(res==10, "number of headers incorrect"); + fail_unless(blkidx==485, "blkidx incorrect"); + fail_unless(headersize==blkidx, "headersize incorrect"); + fail_unless(dm_list_length(&mimelist)==10, "number of message-headers incorrect"); dm_list_free(&mimelist.start); blkidx = 0; headersize = 0; + p = dbmail_message_new(); + p = dbmail_message_init_with_string(p,g_string_new(multipart_message_part)); + dm_list_init(&mimelist); - res = mime_readheader(raw_message_part, &blkidx, &mimelist, &headersize); - fail_unless(res==5, "number of newlines incorrect"); - fail_unless(blkidx==141, "blkidx incorrect"); - fail_unless(headersize==blkidx+res, "headersize incorrect"); + res = mime_readheader(p, &blkidx, &mimelist, &headersize); + fail_unless(res==3, "number of headers incorrect"); + fail_unless(blkidx==142, "blkidx incorrect"); + fail_unless(headersize==blkidx, "headersize incorrect"); fail_unless(mimelist.total_nodes==3, "number of mime-headers incorrect"); dm_list_free(&mimelist.start); + + dbmail_message_free(m); + dbmail_message_free(p); + } END_TEST @@ -199,9 +240,14 @@ START_TEST(test_mime_fetch_headers) { struct dm_list mimelist; struct mime_record *mr; + struct DbmailMessage *m, *p; + + + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m,g_string_new(multipart_message)); dm_list_init(&mimelist); - mime_fetch_headers(raw_message,&mimelist); + mime_fetch_headers(m,&mimelist); fail_unless(mimelist.total_nodes==10, "number of message-headers incorrect"); mr = (mimelist.start)->data; fail_unless(strcmp(mr->field, "Content-Type")==0, "Field name incorrect"); @@ -209,8 +255,11 @@ START_TEST(test_mime_fetch_headers) dm_list_free(&mimelist.start); + p = dbmail_message_new(); + p = dbmail_message_init_with_string(p,g_string_new(multipart_message_part)); + dm_list_init(&mimelist); - mime_fetch_headers(raw_message_part,&mimelist); + mime_fetch_headers(p,&mimelist); fail_unless(mimelist.total_nodes==3, "number of mime-headers incorrect"); mr = (mimelist.start)->data; fail_unless(strcmp(mr->field, "Content-Disposition")==0, "Field name incorrect"); @@ -218,6 +267,8 @@ START_TEST(test_mime_fetch_headers) dm_list_free(&mimelist.start); + dbmail_message_free(m); + dbmail_message_free(p); } END_TEST @@ -229,10 +280,15 @@ START_TEST(test_mail_address_build_list) int result; struct dm_list targetlist; struct dm_list mimelist; + struct DbmailMessage *m; + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m,g_string_new(multipart_message)); + dm_list_init(&targetlist); dm_list_init(&mimelist); - mime_fetch_headers(raw_message, &mimelist); + + mime_fetch_headers(m, &mimelist); result = mail_address_build_list("Cc", &targetlist, &mimelist); struct element *el; @@ -241,13 +297,159 @@ START_TEST(test_mail_address_build_list) fail_unless(result==0, "mail_address_build_list failed"); fail_unless(targetlist.total_nodes==2,"mail_address_build_list failed"); fail_unless(strcmp((char *)el->data,"nobody@test123.com")==0, "mail_address_build_list failed"); + + dbmail_message_free(m); } END_TEST //int db_fetch_headers(u64_t msguid, mime_message_t * msg) START_TEST(test_db_fetch_headers) { - //res = db_start_msg(msg,stopbound,&level,maxlevel); + u64_t physid; + u64_t user_idnr; + int res; + mime_message_t *message; + struct DbmailMessage *m; + + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message)); + dbmail_message_set_header(m, + "References", + "<20050326155326.1afb0377@ibook.linuks.mine.nu> <20050326181954.GB17389@khazad-dum.debian.net> <20050326193756.77747928@ibook.linuks.mine.nu> "); + dbmail_message_store(m); + + physid = dbmail_message_get_physid(m); + auth_user_exists("testuser1",&user_idnr); + fail_unless(user_idnr > 0, "db_fetch_headers failed. Try adding [testuser1]"); + + sort_and_deliver(m,user_idnr,"INBOX"); + + message = db_new_msg(); + res = db_fetch_headers(m->id, message); + fail_unless(res==0,"db_fetch_headers failed"); + + db_free_msg(message); + dbmail_message_free(m); +} +END_TEST + +START_TEST(test_imap_get_structure) +{ + struct DbmailMessage *message; + char *result; + char *expect = g_new0(char,1024); + GList *l; + + /* multipart */ + message = dbmail_message_new(); + message = dbmail_message_init_with_string(message, g_string_new(multipart_message)); + l = imap_get_structure(GMIME_MESSAGE(message->content), 1); + result = dbmail_imap_plist_as_string(l); + strncpy(expect,"((\"text\" \"html\" NIL NIL NIL NIL 18 2 NIL (\"inline\") NIL NIL) " + "(\"text\" \"plain\" (\"charset\" \"us-ascii\" \"name\" \"testfile\") NIL NIL \"base64\" 434 8 NIL NIL NIL NIL) " + "\"mixed\" (\"boundary\" \"boundary\") NIL NIL NIL)",1024); + fail_unless(strncasecmp(result,expect,1024)==0, "imap_get_structure failed"); + g_list_foreach(l,(GFunc)g_free,NULL); + g_free(result); + dbmail_message_free(message); + + /* outlook multipart */ + message = dbmail_message_new(); + message = dbmail_message_init_with_string(message, g_string_new(outlook_multipart)); + l = imap_get_structure(GMIME_MESSAGE(message->content), 1); + result = dbmail_imap_plist_as_string(l); + strncpy(expect,"((\"text\" \"plain\" (\"charset\" \"iso-8859-1\") NIL NIL \"7bit\" 280 13 NIL NIL NIL NIL) " + "(\"text\" \"html\" (\"charset\" \"iso-8859-1\") NIL NIL \"quoted-printable\" 2866 100 NIL NIL NIL NIL) " + "\"alternative\" (\"boundary\" \"----=_NextPart_000_0009_01C5A579.19D2FA10\") NIL NIL NIL " + "(\"text\" \"plain\" (\"charset\" \"iso-8859-1\") NIL NIL \"quoted-printable\" 83 3 NIL (\"inline\") NIL NIL) " + "\"mixed\" (\"boundary\" \"===============0257742399==\") NIL NIL NIL)",1024); + fail_unless(strncasecmp(result,expect,1024)==0, "imap_get_structure failed"); + g_list_foreach(l,(GFunc)g_free,NULL); + g_free(result); + dbmail_message_free(message); + + /* text/plain */ + message = dbmail_message_new(); + message = dbmail_message_init_with_string(message, g_string_new(rfc822)); + l = imap_get_structure(GMIME_MESSAGE(message->content), 1); + result = dbmail_imap_plist_as_string(l); + strncpy(expect,"(\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 34 4 NIL NIL NIL NIL)",1024); + fail_unless(strncasecmp(result,expect,1024)==0, "imap_get_structure failed"); + g_list_foreach(l,(GFunc)g_free,NULL); + g_free(result); + g_free(expect); + dbmail_message_free(message); + +} +END_TEST + +START_TEST(test_imap_get_envelope) +{ + struct DbmailMessage *message; + char *result, *expect; + GList *l = NULL; + + expect = g_new0(char, 1024); + + /* text/plain */ + message = dbmail_message_new(); + message = dbmail_message_init_with_string(message, g_string_new(rfc822)); + l = imap_get_envelope(GMIME_MESSAGE(message->content)); + strncpy(expect,"(\"Thu, 01 Jan 1970 00:00:00 +0000\" \"dbmail test message\" ((NIL NIL \"somewher\" \"foo.org\")) ((NIL NIL \"somewher\" \"foo.org\")) ((NIL NIL \"somewher\" \"foo.org\")) ((NIL NIL \"testuser\" \"foo.org\")) NIL NIL NIL NIL)",1024); + result = dbmail_imap_plist_as_string(l); + fail_unless(strncasecmp(result,expect,1024)==0, "imap_get_envelope failed"); + + g_list_foreach(l,(GFunc)g_free,NULL); + dbmail_message_free(message); + g_list_free(l); + g_free(result); + +} +END_TEST + +START_TEST(test_imap_get_partspec) +{ + struct DbmailMessage *message; + GMimeObject *object; + char *result, *expect; + + expect = g_new0(char, 1024); + + /* text/plain */ + message = dbmail_message_new(); + message = dbmail_message_init_with_string(message, g_string_new(rfc822)); + + object = imap_get_partspec(GMIME_OBJECT(message->content),"HEADER"); + result = imap_get_logical_part(object,"HEADER"); + printf("\n[%s]\n", result); + + object = imap_get_partspec(GMIME_OBJECT(message->content),"TEXT"); + result = imap_get_logical_part(object,"TEXT"); + printf("\n[%s]\n", result); + + dbmail_message_free(message); + + /* multipart */ + + message = dbmail_message_new(); + message = dbmail_message_init_with_string(message, g_string_new(multipart_message)); + + object = imap_get_partspec(GMIME_OBJECT(message->content),"1.TEXT"); + result = imap_get_logical_part(object,"TEXT"); + printf("\n[%s]\n", result); + + object = imap_get_partspec(GMIME_OBJECT(message->content),"1.HEADER"); + result = imap_get_logical_part(object,"HEADER"); + printf("\n[%s]\n", result); + + object = imap_get_partspec(GMIME_OBJECT(message->content),"2.MIME"); + result = imap_get_logical_part(object,"MIME"); + printf("\n[%s]\n", result); + + + g_free(result); + g_free(expect); + } END_TEST @@ -452,6 +654,9 @@ Suite *dbmail_suite(void) tcase_add_checked_fixture(tc_session, setup, teardown); tcase_add_test(tc_session, test_imap_session_new); tcase_add_test(tc_session, test_imap_bodyfetch); + tcase_add_test(tc_session, test_imap_get_structure); + tcase_add_test(tc_session, test_imap_get_envelope); + tcase_add_test(tc_session, test_imap_get_partspec); tcase_add_checked_fixture(tc_rfcmsg, setup, teardown); tcase_add_test(tc_rfcmsg, test_db_fetch_headers); diff --git a/check_dbmail_message.c b/check_dbmail_message.c index c449782c..42fd3d8f 100644 --- a/check_dbmail_message.c +++ b/check_dbmail_message.c @@ -31,23 +31,14 @@ * */ -#include <stdlib.h> #include <check.h> -#include <gmime/gmime.h> -#include <stdio.h> -#include <string.h> - #include "check_dbmail.h" -#include "debug.h" -#include "db.h" -#include "auth.h" -#include "dbmail-message.h" extern char *configFile; extern db_param_t _db_params; -extern char *raw_message; -extern char *raw_message_part; +extern char *multipart_message; +extern char *multipart_message_part; extern char *raw_lmtp_data; /* @@ -128,16 +119,29 @@ START_TEST(test_dbmail_message_get_class) dbmail_message_free(m); } END_TEST + //struct DbmailMessage * dbmail_message_retrieve(struct DbmailMessage *self, u64_t physid, int filter); START_TEST(test_dbmail_message_retrieve) { - struct DbmailMessage *m = dbmail_message_new(); - u64_t physid = 191967; - m = dbmail_message_retrieve(m,physid,DBMAIL_MESSAGE_FILTER_HEAD); - fail_unless(m != NULL, "dbmail_message_retrieve failed"); - fail_unless(m->content != NULL, "dbmail_message_retrieve failed"); + struct DbmailMessage *m, *n; + u64_t physid; + + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message)); + dbmail_message_set_header(m, + "References", + "<20050326155326.1afb0377@ibook.linuks.mine.nu> <20050326181954.GB17389@khazad-dum.debian.net> <20050326193756.77747928@ibook.linuks.mine.nu> "); + dbmail_message_store(m); + + physid = dbmail_message_get_physid(m); + + n = dbmail_message_new(); + n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_HEAD); + fail_unless(n != NULL, "dbmail_message_retrieve failed"); + fail_unless(n->content != NULL, "dbmail_message_retrieve failed"); dbmail_message_free(m); + dbmail_message_free(n); } END_TEST //struct DbmailMessage * dbmail_message_init_with_string(struct DbmailMessage *self, const GString *content); @@ -146,13 +150,13 @@ START_TEST(test_dbmail_message_init_with_string) struct DbmailMessage *m; GTuples *t; m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message)); t = g_relation_select(m->headers, (gpointer)"Received", 0); fail_unless(t->len==2,"Too few headers in tuple"); dbmail_message_set_class(m,DBMAIL_MESSAGE_PART); - m = dbmail_message_init_with_string(m, g_string_new(raw_message_part)); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message_part)); dbmail_message_free(m); } @@ -160,20 +164,20 @@ END_TEST START_TEST(test_dbmail_message_to_string) { - char *decoded, *encoded; + char *result; + GString *s; struct DbmailMessage *m; - m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); + s = g_string_new(multipart_message); - decoded = dbmail_message_to_string(m, FALSE); - encoded = dbmail_message_to_string(m, TRUE); - - /* FIXME: add some checks here */ + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m, s); - g_free(encoded); - g_free(decoded); + result = dbmail_message_to_string(m); + fail_unless(strlen(result)==s->len, "dbmail_message_to_string failed"); + g_string_free(s,TRUE); + g_free(result); dbmail_message_free(m); } END_TEST @@ -190,13 +194,19 @@ END_TEST START_TEST(test_dbmail_message_hdrs_to_string) { char *result; - struct DbmailMessage *m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); - result = dbmail_message_hdrs_to_string(m, FALSE); - fail_unless(strlen(result)==484, "dbmail_message_hdrs_to_string failed"); - g_free(result); + GString *s; + struct DbmailMessage *m; + + s = g_string_new(multipart_message); + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m, s); - dbmail_message_free(m); + result = dbmail_message_hdrs_to_string(m); + fail_unless(strlen(result)==485, "dbmail_message_hdrs_to_string failed"); + + g_string_free(s,TRUE); + dbmail_message_free(m); + g_free(result); } END_TEST @@ -205,12 +215,18 @@ END_TEST START_TEST(test_dbmail_message_body_to_string) { char *result; - struct DbmailMessage *m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); - result = dbmail_message_body_to_string(m, FALSE); - fail_unless(strlen(result)==1046, "dbmail_message_body_to_string failed"); + GString *s; + struct DbmailMessage *m; + + s = g_string_new(multipart_message); + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m,s); + result = dbmail_message_body_to_string(m); + fail_unless(strlen(result)==1045, "dbmail_message_body_to_string failed"); + + dbmail_message_free(m); + g_string_free(s,TRUE); g_free(result); - dbmail_message_free(m); } END_TEST @@ -219,11 +235,18 @@ END_TEST START_TEST(test_dbmail_message_get_rfcsize) { unsigned result; - struct DbmailMessage *m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); + GString *s; + struct DbmailMessage *m; + + s = g_string_new(multipart_message); + m = dbmail_message_new(); + m = dbmail_message_init_with_string(m,s); result = dbmail_message_get_rfcsize(m); + fail_unless(result==1572, "dbmail_message_get_rfcsize failed"); - dbmail_message_free(m); + + g_string_free(s,TRUE); + dbmail_message_free(m); } END_TEST @@ -241,11 +264,11 @@ START_TEST(test_dbmail_message_new_from_stream) struct DbmailMessage *m; u64_t whole_message_size = 0; fd = tmpfile(); - fprintf(fd, "%s", raw_message); + fprintf(fd, "%s", multipart_message); fseek(fd,0,0); m = dbmail_message_new_from_stream(fd, DBMAIL_STREAM_PIPE); whole_message_size = dbmail_message_get_size(m, FALSE); - fail_unless(whole_message_size == strlen(raw_message), + fail_unless(whole_message_size == strlen(multipart_message), "read_whole_message_stream returned wrong message_size"); fseek(fd,0,0); @@ -253,9 +276,9 @@ START_TEST(test_dbmail_message_new_from_stream) m = dbmail_message_new_from_stream(fd, DBMAIL_STREAM_LMTP); whole_message_size = dbmail_message_get_size(m, FALSE); - // note: we're comparing with raw_message not raw_lmtp_data because - // raw_message == raw_lmtp_data - crlf - end-dot - fail_unless(whole_message_size == strlen(raw_message), + // note: we're comparing with multipart_message not raw_lmtp_data because + // multipart_message == raw_lmtp_data - crlf - end-dot + fail_unless(whole_message_size == strlen(multipart_message), "read_whole_message_network returned wrong message_size"); dbmail_message_free(m); } @@ -264,7 +287,7 @@ END_TEST START_TEST(test_dbmail_message_set_header) { struct DbmailMessage *m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message)); dbmail_message_set_header(m, "X-Foobar","Foo Bar"); fail_unless(dbmail_message_get_header(m, "X-Foobar")!=NULL, "set_header failed"); dbmail_message_free(m); @@ -278,8 +301,8 @@ START_TEST(test_dbmail_message_get_header) struct DbmailMessage *m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); - t = dbmail_message_hdrs_to_string(m, FALSE); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message)); + t = dbmail_message_hdrs_to_string(m); h = dbmail_message_init_with_string(h, g_string_new(t)); g_free(t); @@ -298,7 +321,7 @@ END_TEST START_TEST(test_dbmail_message_cache_headers) { struct DbmailMessage *m = dbmail_message_new(); - m = dbmail_message_init_with_string(m, g_string_new(raw_message)); + m = dbmail_message_init_with_string(m, g_string_new(multipart_message)); dbmail_message_set_header(m, "References", "<20050326155326.1afb0377@ibook.linuks.mine.nu> <20050326181954.GB17389@khazad-dum.debian.net> <20050326193756.77747928@ibook.linuks.mine.nu> "); diff --git a/check_dbmail_server.c b/check_dbmail_server.c index c761cdcd..c1839882 100644 --- a/check_dbmail_server.c +++ b/check_dbmail_server.c @@ -31,21 +31,7 @@ * */ -#include <stdlib.h> #include <check.h> -#include <stdio.h> -#include <string.h> - -#include "dbmail.h" -#include "debug.h" -#include "db.h" -#include "dm_cidr.h" -#include "pool.h" -#include "server.h" -#include "check.h" -#include "misc.h" -#include <gmime/gmime.h> - #include "check_dbmail.h" extern char *configFile; diff --git a/check_dbmail_user.c b/check_dbmail_user.c index 944874cf..ec3e161f 100644 --- a/check_dbmail_user.c +++ b/check_dbmail_user.c @@ -31,19 +31,7 @@ * */ -#include <stdlib.h> #include <check.h> -#include <gmime/gmime.h> -#include <stdio.h> -#include <string.h> - -#include "dbmail.h" -#include "dbmailtypes.h" -#include "debug.h" -#include "auth.h" -#include "db.h" -#include "dbmail-user.h" - #include "check_dbmail.h" extern char *configFile; diff --git a/check_dbmail_util.c b/check_dbmail_util.c index 6581c60b..d8c20c28 100644 --- a/check_dbmail_util.c +++ b/check_dbmail_util.c @@ -31,18 +31,7 @@ * */ -#include <stdlib.h> #include <check.h> -#include <gmime/gmime.h> -#include <stdio.h> -#include <string.h> - -#include "dbmail.h" -#include "dbmailtypes.h" -#include "debug.h" -#include "auth.h" -#include "db.h" - #include "check_dbmail.h" extern char *configFile; @@ -23,20 +23,7 @@ * \brief read configuration values from a config file */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - - #include "dbmail.h" -#include "debug.h" - -/* include for iniparser */ -#include "lib/iniparser-2.14/src/iniparser.h" - -#include <glib.h> -#include <assert.h> -#include <errno.h> /** dictionary which holds the configuration */ static dictionary *config_dict = NULL; @@ -27,18 +27,7 @@ * place in the mysql/ and pgsql/ directories */ -#include <stdio.h> -#include <time.h> -#include <stdlib.h> -#include <limits.h> -#include <string.h> -#include <sys/types.h> -#include <assert.h> -#include "db.h" #include "dbmail.h" -#include "dbmail-message.h" -#include "auth.h" -#include "misc.h" static const char *db_flag_desc[] = { "seen_flag", @@ -1713,7 +1702,10 @@ int db_delete_mailbox(u64_t mailbox_idnr, int only_empty, int db_send_message_lines(void *fstream, u64_t message_idnr, long lines, int no_end_dot) { + struct DbmailMessage *msg; + u64_t physmessage_id = 0; + char *raw; char *buffer = NULL; int buffer_pos; const char *nextpos; @@ -1723,39 +1715,18 @@ int db_send_message_lines(void *fstream, u64_t message_idnr, int n; const char *query_result; + + trace(TRACE_DEBUG, "%s,%s: request for [%ld] lines", __FILE__, __func__, lines); /* first find the physmessage_id */ - snprintf(query, DEF_QUERYSIZE, - "SELECT physmessage_id FROM %smessages " - "WHERE message_idnr = '%llu'",DBPFX, message_idnr); - if (db_query(query) == -1) { - trace(TRACE_ERROR, "%s,%s: error executing query", - __FILE__, __func__); - return DM_SUCCESS; - } - physmessage_id = db_get_result_u64(0, 0); - db_free_result(); - - buffer = dm_malloc(WRITE_BUFFER_SIZE * 2); - if (buffer == NULL) { - trace(TRACE_ERROR, "%s,%s: error allocating memory for buffer", - __FILE__, __func__); - return DM_SUCCESS; - } + if (db_get_physmessage_id(message_idnr, &physmessage_id) != DM_SUCCESS) + return DM_EGENERAL; - snprintf(query, DEF_QUERYSIZE, - "SELECT messageblk FROM %smessageblks " - "WHERE physmessage_id='%llu' " - "ORDER BY messageblk_idnr ASC",DBPFX, physmessage_id); - trace(TRACE_DEBUG, "%s,%s: executing query [%s]", - __FILE__, __func__, query); - - if (db_query(query) == -1) { - dm_free(buffer); - return DM_SUCCESS; - } + msg = dbmail_message_new(); + msg = dbmail_message_retrieve(msg, physmessage_id, DBMAIL_MESSAGE_FILTER_FULL); + raw = dbmail_message_to_string(msg); trace(TRACE_DEBUG, "%s,%s: sending [%ld] lines from message [%llu]", __FILE__, @@ -3478,8 +3449,9 @@ int db_get_rfcsize(u64_t msg_idnr, u64_t mailbox_idnr, u64_t * rfc_size) int db_get_main_header(u64_t msg_idnr, struct dm_list *hdrlist) { - const char *query_result; - int result; + struct mime_record *mr; + char *field, *value; + int i,j; if (!hdrlist) return DM_SUCCESS; @@ -3488,65 +3460,50 @@ int db_get_main_header(u64_t msg_idnr, struct dm_list *hdrlist) dm_list_free(&hdrlist->start); dm_list_init(hdrlist); - - snprintf(query, DEF_QUERYSIZE, - "SELECT messageblk " - "FROM %smessageblks blk, %smessages msg " - "WHERE blk.physmessage_id = msg.physmessage_id " - "AND msg.message_idnr = '%llu' " - "ORDER BY blk.messageblk_idnr ASC",DBPFX,DBPFX, msg_idnr); - + + snprintf(query, DEF_QUERYSIZE, "SELECT headername, headervalue " + "FROM %sheadervalue " + "JOIN %sheadername ON %sheadername.id=%sheadervalue.headername_id " + "JOIN %sphysmessage ON %sphysmessage.id=%sheadervalue.physmessage_id " + "JOIN %smessages ON %smessages.physmessage_id=%sphysmessage.id " + "WHERE %smessages.message_idnr='%llu'", + DBPFX, DBPFX, DBPFX, DBPFX, DBPFX, + DBPFX, DBPFX, DBPFX, DBPFX, DBPFX, + DBPFX, msg_idnr); + if (db_query(query) == -1) { - trace(TRACE_ERROR, "%s,%s: could not get message header", + trace(TRACE_ERROR, "%s,%s: could not get message headers", __FILE__, __func__); return DM_EQUERY; } - if (db_num_rows() > 0) { - query_result = db_get_result(0, 0); - if (!query_result) { - trace(TRACE_ERROR, - "%s,%s: no header for message found", - __FILE__, __func__); - db_free_result(); - return DM_EQUERY; - } - } else { - trace(TRACE_ERROR, - "%s,%s: no message blocks found for message", + + j = db_num_rows(); + + if (j <= 0) { + trace(TRACE_ERROR, "%s,%s: no message headers found for message", __FILE__, __func__); db_free_result(); return DM_EQUERY; } + + mr = g_new0(struct mime_record, 1); + for (i=0; i<j; i++) { + + field = (char *)db_get_result(i, 0); + value = (char *)db_get_result(i, 1); + + if (! mr) + trace(TRACE_FATAL,"%s,%s: oom", __FILE__, __func__); - result = mime_fetch_headers(query_result, hdrlist); - - db_free_result(); - - if (result == -1) { - /* parse error */ - trace(TRACE_ERROR, - "%s,%s: error parsing header of message [%llu]", - __FILE__, __func__, msg_idnr); - if (hdrlist->start) { - dm_list_free(&hdrlist->start); - dm_list_init(hdrlist); - } - return -3; + g_strlcpy(mr->field, field, MIME_FIELD_MAX); + g_strlcpy(mr->value, value, MIME_VALUE_MAX); + dm_list_nodeadd(hdrlist, mr, sizeof(*mr)); } + g_free(mr); - if (result == -2) { - /* out of memory */ - trace(TRACE_ERROR, "%s,%s: out of memory", __FILE__, - __func__); - if (hdrlist->start) { - dm_list_free(&hdrlist->start); - dm_list_init(hdrlist); - } - return -2; - } + db_free_result(); - /* success ! */ return DM_SUCCESS; } @@ -29,17 +29,7 @@ #ifndef _DB_H #define _DB_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "debug.h" #include "dbmail.h" -#include "dbmailtypes.h" -#include "mime.h" -#include "list.h" -#include "memblock.h" - #define DEF_QUERYSIZE 1024 #define DUMP_BUF_SIZE 1024 diff --git a/dbmail-imapsession.c b/dbmail-imapsession.c index 760d925a..db7985fd 100644 --- a/dbmail-imapsession.c +++ b/dbmail-imapsession.c @@ -19,35 +19,12 @@ /* $Id$ * - * imaputil.c + * dm_imaputil.c * * IMAP-server utility functions implementations */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <assert.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <stdarg.h> -#include <time.h> -#include <ctype.h> -#include <unistd.h> -#include <errno.h> - #include "dbmail.h" -#include "imaputil.h" -#include "imap4.h" -#include "debug.h" -#include "db.h" -#include "memblock.h" -#include "dm_search.h" -#include "dbmsgbuf.h" -#include "rfcmsg.h" -#include "dbmail-imapsession.h" #ifndef MAX_LINESIZE #define MAX_LINESIZE (10*1024) @@ -85,11 +62,6 @@ extern const char *imap_flag_desc_escaped[]; static int _imap_session_fetch_parse_partspec(struct ImapSession *self, int idx); static int _imap_session_fetch_parse_octet_range(struct ImapSession *self, int idx); -static GList * _imap_get_structure(mime_message_t * msg, int show_extension_data); -static GList * _imap_get_addresses(struct mime_record *mr); -static GList * _imap_get_envelope(struct dm_list *rfcheader); -static GList * _imap_get_mime_parameters(struct mime_record *mr, int force_subtype, int only_extension); - static void _imap_show_body_sections(struct ImapSession *self); static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data); @@ -193,634 +165,92 @@ void dbmail_imap_session_delete(struct ImapSession * self) * * ************************************************************************************/ -static u64_t _imap_cache_update(struct ImapSession *self, message_filter_t filter) +#define IMAP_CACHE_MEMDUMP 1 +#define IMAP_CACHE_TMPDUMP 2 + +static u64_t _imap_cache_set_dump(char *buf, int dumptype) { u64_t outcnt = 0; - char *buf = NULL; - struct DbmailMessage *msg = NULL; - - switch (filter) { - case DBMAIL_MESSAGE_FILTER_FULL: - if (cached_msg.file_dumped == 0 || cached_msg.num != self->msg_idnr) { + char *rfc = get_crlf_encoded(buf); - msg = db_init_fetch(self->msg_idnr, filter); - buf = dbmail_message_to_string(msg, TRUE); // crlf encoded - - mrewind(cached_msg.memdump); - mrewind(cached_msg.tmpdump); - - /* update both MEM buffers */ - mwrite(buf, strlen(buf), cached_msg.tmpdump); - outcnt = (u64_t)mwrite(buf, strlen(buf), cached_msg.memdump); - cached_msg.dumpsize = outcnt; - - if (cached_msg.num != self->msg_idnr) { - /* if there is a parsed msg in the cache it will be invalid now */ - if (cached_msg.msg_parsed) { - cached_msg.msg_parsed = 0; - db_free_msg(&cached_msg.msg); - } - cached_msg.num = self->msg_idnr; - } - cached_msg.file_dumped = 1; - - mrewind(cached_msg.memdump); - mrewind(cached_msg.tmpdump); - } + switch (dumptype) { + case IMAP_CACHE_MEMDUMP: + mrewind(cached_msg.memdump); + outcnt = mwrite(rfc, strlen(rfc), cached_msg.memdump); + mrewind(cached_msg.memdump); break; - - /* these two only update the temp MEM buffer */ - case DBMAIL_MESSAGE_FILTER_HEAD: - msg = db_init_fetch(self->msg_idnr, filter); - buf = dbmail_message_hdrs_to_string(msg, TRUE); - + case IMAP_CACHE_TMPDUMP: mrewind(cached_msg.tmpdump); - outcnt = mwrite(buf, strlen(buf), cached_msg.tmpdump); + outcnt = mwrite(rfc, strlen(rfc), cached_msg.tmpdump); mrewind(cached_msg.tmpdump); break; - - case DBMAIL_MESSAGE_FILTER_BODY: - msg = db_init_fetch(self->msg_idnr, filter); - buf = dbmail_message_body_to_string(msg, TRUE); - - mrewind(cached_msg.tmpdump); - outcnt = mwrite(buf, strlen(buf), cached_msg.tmpdump); - mrewind(cached_msg.tmpdump); - break; - } - - trace(TRACE_DEBUG, "%s,%s: cached [%llu] bytes", __FILE__, __func__, outcnt); - - g_free(buf); - dbmail_message_free(msg); + g_free(rfc); return outcnt; } - - -/* - * _imap_get_structure() - * - * retrieves the MIME-IMB structure of a message. The msg should be in the format - * as build by db_fetch_headers(). - * - * shows extension data if show_extension_data != 0 - * - * returns GList on success, NULL on error - */ - -GList * _imap_get_structure(mime_message_t * msg, int show_extension_data) +static u64_t _imap_cache_update(struct ImapSession *self, message_filter_t filter) { - struct mime_record *mr; - struct element *curr; - struct dm_list *header_to_use; - mime_message_t rfcmsg; - char *subtype, *extension, *newline; - int is_mime_multipart = 0, is_rfc_multipart = 0; - int rfc822 = 0; - - GList *tlist = NULL, *list = NULL; - GString *tmp = g_string_new(""); - gchar *pstring; - - trace(TRACE_DEBUG,"%s,%s", __FILE__,__func__); - - mime_findfield("content-type", &msg->mimeheader, &mr); - is_mime_multipart = (mr - && strncasecmp(mr->value, "multipart", strlen("multipart")) == 0 - && !msg->message_has_errors); - - mime_findfield("content-type", &msg->rfcheader, &mr); - is_rfc_multipart = (mr - && strncasecmp(mr->value, "multipart", strlen("multipart")) == 0 - && !msg->message_has_errors); - - /* eddy */ - rfc822 = (mr && strncasecmp(mr->value, "message/rfc822", strlen("message/rfc822")) == 0); - - if (rfc822 || (!is_rfc_multipart && !is_mime_multipart)) { - /* show basic fields: - * content-type, content-subtype, (parameter list), - * content-id, content-description, content-transfer-encoding, - * size - */ - - if (msg->mimeheader.start == NULL) - header_to_use = &msg->rfcheader; /* we're dealing with a single-part RFC msg here */ - else - header_to_use = &msg->mimeheader; /* we're dealing with a pure-MIME header here */ - - mime_findfield("content-type", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - - tlist = _imap_get_mime_parameters(mr, 1, 0); - - tmp = g_list_join(tlist," "); - - dbmail_imap_plist_free(tlist); - tlist = NULL; - - list = g_list_append(list, g_strdup(tmp->str)); - } else - list = g_list_append(list, g_strdup("\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\")")); /* default */ - - mime_findfield("content-id", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - } else - list = g_list_append(list, g_strdup("NIL")); - - mime_findfield("content-description", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - } else - list = g_list_append(list, g_strdup("NIL")); - - mime_findfield("content-transfer-encoding", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - } else - list = g_list_append(list, g_strdup("\"7BIT\"")); - - /* now output size */ - /* add msg->bodylines because \n is dumped as \r\n */ - if (msg->mimeheader.start && msg->rfcheader.start) - list = g_list_append_printf(list, "%llu", - msg->bodysize + msg->mimerfclines + - msg->rfcheadersize - msg->rfcheaderlines); - else - list = g_list_append_printf(list, "%llu", msg->bodysize + msg->bodylines); - - - /* now check special cases, first case: message/rfc822 */ - mime_findfield("content-type", header_to_use, &mr); - if (mr && strncasecmp(mr->value, "message/rfc822", strlen("message/rfc822")) == 0 - && header_to_use != &msg->rfcheader) { - /* msg/rfc822 found; extra items to be displayed: - * (a) body envelope of rfc822 msg - * (b) body structure of rfc822 msg - * (c) msg size (lines) - */ - - tlist = _imap_get_envelope(&msg->rfcheader); - - list = g_list_append(list, dbmail_imap_plist_as_string(tlist)); - - dbmail_imap_plist_free(tlist); - tlist = NULL; - - memmove(&rfcmsg, msg, sizeof(rfcmsg)); - rfcmsg.mimeheader.start = NULL; /* forget MIME-part */ - - /* start recursion */ - tlist = _imap_get_structure(&rfcmsg, show_extension_data); - - list = g_list_append(list, dbmail_imap_plist_as_string(tlist)); - - dbmail_imap_plist_free(tlist); - tlist = NULL; - - /* output # of lines */ - list = g_list_append_printf(list, "%llu", msg->bodylines); - } - /* now check second special case: text - * NOTE: if 'content-type' is absent, TEXT is assumed - */ - if ((mr && strncasecmp(mr->value, "text", strlen("text")) == 0) || !mr) { - /* output # of lines */ - if (msg->mimeheader.start && msg->rfcheader.start) - list = g_list_append_printf(list, "%llu", msg->mimerfclines); - else - list = g_list_append_printf(list, "%llu", msg->bodylines); - } + u64_t tmpcnt = 0, outcnt = 0; + char *buf = NULL; + char *rfc = NULL; - if (show_extension_data) { - mime_findfield("content-md5", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append_printf(list, dbmail_imap_astring_as_string(mr->value)); - } else - list = g_list_append(list, g_strdup("NIL")); - - mime_findfield("content-disposition", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - tlist = _imap_get_mime_parameters(mr, 0, 0); - list = g_list_append(list, dbmail_imap_plist_as_string(tlist)); - dbmail_imap_plist_free(tlist); - tlist = NULL; - } else - list = g_list_append(list, g_strdup("NIL")); - - mime_findfield("content-language", header_to_use, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - } else - list = g_list_append(list, g_strdup("NIL")); - } + if (cached_msg.file_dumped == 1 && cached_msg.num == self->msg_idnr) { + outcnt = cached_msg.dumpsize; } else { - /* check for a multipart message */ - if (is_rfc_multipart || is_mime_multipart) { - curr = dm_list_getstart(&msg->children); - tmp = g_string_new(""); - while (curr) { - tlist = _imap_get_structure((mime_message_t *) curr->data, show_extension_data); - - pstring = dbmail_imap_plist_as_string(tlist); - - g_string_append_printf(tmp, "%s", pstring); - - g_free(pstring); - - dbmail_imap_plist_free(tlist); - tlist = NULL; - - curr = curr->nextnode; - } - list = g_list_append(list, g_strdup(tmp->str)); - - /* show multipart subtype */ - if (is_mime_multipart) - mime_findfield("content-type", &msg->mimeheader, &mr); - else - mime_findfield("content-type", &msg->rfcheader, &mr); - - subtype = strchr(mr->value, '/'); - extension = strchr(subtype, ';'); - - if (!subtype) - list = g_list_append(list, g_strdup("NIL")); - else { - if (!extension) { - newline = strchr(subtype, '\n'); - if (!newline) - return NULL; - - *newline = 0; - list = g_list_append(list, dbmail_imap_astring_as_string(subtype + 1)); - *newline = '\n'; - } else { - *extension = 0; - list = g_list_append(list, dbmail_imap_astring_as_string(subtype + 1)); - *extension = ';'; - } - } - - /* show extension data (after subtype) */ - if (extension && show_extension_data) { - tlist = _imap_get_mime_parameters(mr, 0, 1); - - tmp = g_list_join(tlist," "); - - dbmail_imap_plist_free(tlist); - tlist = NULL; - - list = g_list_append(list, g_strdup(tmp->str)); - - /* FIXME: should give body-disposition & body-language here */ - list = g_list_append(list, g_strdup("NIL NIL")); - } - } else { - /* ??? */ + /* causing double-frees here. Defer freeing dmsg to close_cache() */ + /* + if (cached_msg.dmsg != NULL) { + dbmail_message_free(cached_msg.dmsg); + cached_msg.dmsg = NULL; } - } - g_string_free(tmp,1); - return list; -} - - -/* - * _imap_get_envelope() - * - * retrieves the body envelope of an RFC-822 msg - * - * returns GList of char * elements - * - */ -static GList * _imap_get_envelope(struct dm_list *rfcheader) -{ - struct mime_record *mr; - int idx; - GList * list = NULL; + */ - trace(TRACE_DEBUG,"%s,%s", __FILE__,__func__); + cached_msg.dmsg = db_init_fetch(self->msg_idnr, DBMAIL_MESSAGE_FILTER_FULL); + buf = dbmail_message_to_string(cached_msg.dmsg); - mime_findfield("date", rfcheader, &mr); - if (mr && strlen(mr->value) > 0) - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - else - list = g_list_append(list, g_strdup("NIL")); - - mime_findfield("subject", rfcheader, &mr); - if (mr && strlen(mr->value) > 0) - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - else - list = g_list_append(list, g_strdup("NIL")); - - /* now from, sender, reply-to, to, cc, bcc, in-reply-to fields; - * note that multiple mailaddresses are separated by ',' - */ - GString *tmp = g_string_new(""); - for (idx = 0; envelope_items[idx]; idx++) { - mime_findfield(envelope_items[idx], rfcheader, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_plist_as_string(_imap_get_addresses(mr))); - } else if (strcasecmp(envelope_items[idx], "reply-to") == 0) { - mime_findfield("from", rfcheader, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_plist_as_string(_imap_get_addresses(mr))); - } else - list = g_list_append(list, g_strdup("((NIL NIL \"nobody\" \"nowhere.nirgendwo\"))")); - } else if (strcasecmp(envelope_items[idx], "sender") == 0) { - mime_findfield("from", rfcheader, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_plist_as_string(_imap_get_addresses(mr))); - } else - list = g_list_append(list, g_strdup("((NIL NIL \"nobody\" \"nowhere.nirgendwo\"))")); - } else - list = g_list_append(list,g_strdup("NIL")); - } - - mime_findfield("in-reply-to", rfcheader, &mr); - if (mr && strlen(mr->value) > 0) { - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - } else - list = g_list_append(list, g_strdup("NIL")); - - mime_findfield("message-id", rfcheader, &mr); - if (mr && strlen(mr->value) > 0) - list = g_list_append(list, dbmail_imap_astring_as_string(mr->value)); - else - list = g_list_append(list, g_strdup("NIL")); - g_string_free(tmp,1); - return list; -} - - -/* - * _imap_get_addresses() - * - * gives an address list - */ -static GList * _imap_get_addresses(struct mime_record *mr) -{ - int delimiter, i, inquote, start, has_split; - char savechar; - char *value; - - GList * list = NULL; - GList * sublist = NULL; - GString * tmp = g_string_new(""); + outcnt = _imap_cache_set_dump(buf,IMAP_CACHE_MEMDUMP); + tmpcnt = _imap_cache_set_dump(buf,IMAP_CACHE_TMPDUMP); - trace(TRACE_DEBUG,"%s,%s: [%s]", __FILE__,__func__, mr->value); - - /* find ',' to split up multiple addresses */ - delimiter = 0; - - do { - sublist = NULL; - start = delimiter; - - for (inquote = 0; mr->value[delimiter] && !(mr->value[delimiter] == ',' && !inquote); delimiter++) - if (mr->value[delimiter] == '\"') - inquote ^= 1; - - if (mr->value[delimiter]) - mr->value[delimiter] = 0; /* replace ',' by NULL-termination */ - else - delimiter = -1; /* this will be the last one */ - - /* the address currently being processed is now contained within - * &mr->value[start] 'till first '\0' - */ - - /* possibilities for the mail address: - * - name <user@domain> - * - "name" <user@domain> - * - <user@domain> - * - user@domain - * - user@domain (Name) - * scan for '<' to determine which case we should be dealing with; - */ - - for (i = start, inquote = 0; mr->value[i] && !(mr->value[i] == '<' && !inquote); i++) - if (mr->value[i] == '\"') - inquote ^= 1; - - if (mr->value[i]) { - if (i > start + 2) { - /* name is contained in &mr->value[start] untill &mr->value[i-2] */ - /* name might contain quotes */ - savechar = mr->value[i - 1]; - mr->value[i - 1] = '\0'; /* terminate string */ - if ( !g_str_has_prefix(&mr->value[start],"\"") && !g_str_has_suffix(&mr->value[start],"\"") ) - value=g_strdup_printf("\"%s\"", &mr->value[start]); - else - value=g_strdup(&mr->value[start]); - - trace(TRACE_DEBUG,"%s,%s: found [%s]", __FILE__, __func__, value); - sublist = g_list_append(sublist, dbmail_imap_astring_as_string(value)); - g_free(value); - - - mr->value[i - 1] = savechar; - - } else - sublist = g_list_append(sublist, g_strdup("NIL")); - - start = i + 1; /* skip to after '<' */ - } else - sublist = g_list_append(sublist, g_strdup("NIL")); - - sublist = g_list_append(sublist, g_strdup("NIL")); /* source route ?? smtp at-domain-list ?? */ - - /* - * now display user domainname; &mr->value[start] is starting point - */ + assert(tmpcnt==outcnt); - g_string_printf(tmp,"\""); - // added a check for whitespace within the address (not good) - for (i = start, has_split = 0; mr->value[i] && mr->value[i] != '>' && !isspace(mr->value[i]); i++) { - if (mr->value[i] == '@') { - tmp = g_string_append(tmp, "\" \""); - has_split = 1; - } else { - if (mr->value[i] == '"') - tmp = g_string_append(tmp, "\\"); - g_string_append_printf(tmp, "%c", mr->value[i]); - } - } - - if (!has_split) - tmp = g_string_append(tmp, "\" \"\""); /* '@' did not occur */ - else - tmp = g_string_append(tmp, "\""); + cached_msg.dumpsize = outcnt; - sublist = g_list_append(sublist,g_strdup(tmp->str)); + if (cached_msg.num != self->msg_idnr) + cached_msg.num = self->msg_idnr; - if (delimiter > 0) { - mr->value[delimiter++] = ','; /* restore & prepare for next iteration */ - while (isspace(mr->value[delimiter])) - delimiter++; - } - list = g_list_append(list, dbmail_imap_plist_as_string(sublist)); - - } while (delimiter > 0); - - g_list_foreach(sublist, (GFunc)g_free, NULL); - g_list_free(sublist); - sublist = NULL; - g_string_free(tmp,1); - return list; -} - + cached_msg.file_dumped = 1; + mrewind(cached_msg.memdump); + mrewind(cached_msg.tmpdump); -/* - * _imap_get_mime_parameters() - * - * get mime name/value pairs - * - * return GList for conversion to plist - * - * if force_subtype != 0 'NIL' will be outputted if no subtype is specified - * if only_extension != 0 only extension data (after first ';') will be shown - */ -static GList * _imap_get_mime_parameters(struct mime_record *mr, int force_subtype, int only_extension) -{ - GList * list = NULL; - GList * subl = NULL; - GString * tmp = g_string_new(""); - char * tmp2 = g_new(char, 255); - char * tmp3 = g_new(char, 255); - - int idx, delimiter, start, end; - - /* find first delimiter */ - for (delimiter = 0; mr->value[delimiter] && mr->value[delimiter] != ';'; delimiter++); - - /* are there non-whitespace chars after the delimiter? */ - /* looking for the case where the mime type ends with a ";" */ - /* if it is of type "text" it must have a default character set generated */ - end = strlen(mr->value); - for (start = delimiter + 1; (isspace(mr->value[start]) == 0 && start <= end); start++); - end = start - delimiter - 1; - start = 0; - if (end && strstr(mr->value, "text")) - start++; - - if (mr->value[delimiter]) - mr->value[delimiter] = 0; - else - delimiter = -1; - - if (!only_extension) { - /* find main type in value */ - for (idx = 0; mr->value[idx] && mr->value[idx] != '/'; - idx++); - - if (mr->value[idx] && (idx < delimiter || delimiter == -1)) { - mr->value[idx] = 0; - list = g_list_append(list,dbmail_imap_astring_as_string(mr->value)); - list = g_list_append(list,dbmail_imap_astring_as_string(&mr->value[idx + 1])); - - mr->value[idx] = '/'; - } else { - list = g_list_append(list,dbmail_imap_astring_as_string(mr->value)); - list = g_list_append(list, g_strdup(force_subtype ? "NIL" : "")); - } + g_free(buf); + g_free(rfc); } - if (delimiter >= 0) { - /* extra parameters specified */ - mr->value[delimiter] = ';'; - idx = delimiter; - - if (start) - subl = g_list_append(subl, g_strdup("\"CHARSET\" \"US-ASCII\"")); - /* extra params: <name>=<val> [; <name>=<val> [; ...etc...]] - * note that both name and val may or may not be enclosed by - * either single or double quotation marks - */ - - do { - /* skip whitespace */ - for (idx++; isspace(mr->value[idx]); idx++); - if (!mr->value[idx]) - break; /* ?? */ - - /* check if quotation marks are specified */ - if (mr->value[idx] == '\"' || mr->value[idx] == '\'') { - start = ++idx; - while (mr->value[idx] && mr->value[idx] != mr->value[start - 1]) - idx++; - - if (!mr->value[idx] || mr->value[idx + 1] != '=') /* ?? no end quote */ - break; - - end = idx; - idx += 2; /* skip to after '=' */ - } else { - start = idx; - while (mr->value[idx] && mr->value[idx] != '=') - idx++; - - if (!mr->value[idx]) /* ?? no value specified */ - break; - - end = idx; - idx++; /* skip to after '=' */ - } - - subl = g_list_append_printf(subl, "\"%.*s\"", (end - start), &mr->value[start]); - - /* now process the value; practically same procedure */ - - if (mr->value[idx] == '\"' || mr->value[idx] == '\'') { - start = ++idx; - while (mr->value[idx] && mr->value[idx] != mr->value[start - 1]) - idx++; - - if (!mr->value[idx]) /* ?? no end quote */ - break; - - end = idx; - idx++; - } else { - start = idx; - - while (mr->value[idx] && !isspace(mr->value[idx]) && mr->value[idx] != ';') - idx++; - - end = idx; - } - - snprintf(tmp2,255,"\"%.*s\"", (end - start), &mr->value[start]); - mime_unwrap(tmp3,tmp2); - subl = g_list_append_printf(subl, tmp3); - - /* check for more name/val pairs */ - while (mr->value[idx] && mr->value[idx] != ';') - idx++; + + switch (filter) { + /* for these two update the temp MEM buffer */ + case DBMAIL_MESSAGE_FILTER_HEAD: + buf = dbmail_message_hdrs_to_string(cached_msg.dmsg); + outcnt = _imap_cache_set_dump(buf,IMAP_CACHE_TMPDUMP); + g_free(buf); + break; - } while (mr->value[idx]); + case DBMAIL_MESSAGE_FILTER_BODY: + buf = dbmail_message_body_to_string(cached_msg.dmsg); + outcnt = _imap_cache_set_dump(buf,IMAP_CACHE_TMPDUMP); + g_free(buf); + break; + case DBMAIL_MESSAGE_FILTER_FULL: + /* done */ + break; - list = g_list_append(list, dbmail_imap_plist_as_string(subl)); - g_list_foreach(subl, (GFunc)g_free, NULL); - g_list_free(subl); - subl = NULL; - g_string_free(tmp,1); - } else { - list = g_list_append(list, g_strdup("NIL")); } - g_free(tmp2); - g_free(tmp3); - - return list; + + return outcnt; } - - - static int _imap_session_fetch_parse_partspec(struct ImapSession *self, int idx) { /* check for a partspecifier */ @@ -1100,11 +530,13 @@ int dbmail_imap_session_fetch_get_unparsed(struct ImapSession *self, u64_t fetch u64_t lo, hi; u64_t i; + u64_t physid = 0; int j; int result; unsigned nmatching; unsigned fn; + struct DbmailMessage *msg; GList *list = NULL; GList *sublist = NULL; GString *tmp = g_string_new(""); @@ -1132,27 +564,25 @@ int dbmail_imap_session_fetch_get_unparsed(struct ImapSession *self, u64_t fetch for (i = 0; i < nmatching; i++) { if (self->fi->getSize && self->msginfo[i].rfcsize == 0) { /* parse the message to calc the size */ - result = db_fetch_headers(self->msginfo[i].uid, &self->headermsg); + result = db_get_physmessage_id(self->msginfo[i].uid, &physid); if (result == -2) { dbmail_imap_session_printf(self, "\r\n* BYE internal dbase error\r\n"); - return -1; + return DM_EGENERAL; } if (result == -3) { dbmail_imap_session_printf(self, "\r\n* BYE out of memory\r\n"); - return -1; + return DM_EGENERAL; } + msg = dbmail_message_new(); + msg = dbmail_message_retrieve(msg, physid, DBMAIL_MESSAGE_FILTER_FULL); - self->msginfo[i].rfcsize = (self->headermsg.rfcheadersize + - self->headermsg.bodysize + self->headermsg.bodylines); + self->msginfo[i].rfcsize = dbmail_message_get_rfcsize(msg); db_set_rfcsize(self->msginfo[i].rfcsize, self->msginfo[i].uid, ud->mailbox.uid); + + dbmail_message_free(msg); } if (binary_search (ud->mailbox.seq_list, ud->mailbox.exists, self->msginfo[i].uid, &fn) == -1) { - /* this is probably some sync error: - * the msgUID belongs to this mailbox but was not found - * when building the mailbox info - * let's call it fatal and let the client re-connect :) - */ dbmail_imap_session_printf(self, "* BYE internal syncing error\r\n"); return -1; } @@ -1257,6 +687,10 @@ int dbmail_imap_session_get_msginfo_range(struct ImapSession *self, u64_t msg_id return (int)nrows; } +#define SEND_SPACE if (self->fi->isfirstfetchout) \ + self->fi->isfirstfetchout = 0; \ + else \ + dbmail_imap_session_printf(self, " ") int dbmail_imap_session_fetch_get_items(struct ImapSession *self) { @@ -1270,6 +704,7 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) GList *tlist = NULL; GString *tmp = g_string_new(""); + /* check RFC822.SIZE request */ if (self->fi->getSize) { /* ok, try to fetch size from dbase */ @@ -1286,94 +721,36 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) /* update cache */ - if (self->fi->msgparse_needed && self->msg_idnr != cached_msg.num) { - if (! self->fi->msgparse_needed) { - /* don't update cache if only the main header is needed - * but do retrieve this main header - */ - - result = db_get_main_header(self->msg_idnr, &self->headermsg.rfcheader); - - if (result == -1) { - dbmail_imap_session_printf(self, "\r\n* BYE internal dbase error\r\n"); - return -1; - } - - if (result == -2) { - dbmail_imap_session_printf(self, "\r\n* BYE out of memory\r\n"); - return -1; - } - - if (result == -3) { - /* parse error */ - g_string_free(tmp,TRUE); - return 0; - } - - } else { - /* parse message structure */ - if (cached_msg.msg_parsed) - db_free_msg(&cached_msg.msg); - - memset(&cached_msg.msg, 0, sizeof(cached_msg.msg)); - - cached_msg.msg_parsed = 0; - cached_msg.num = -1; - cached_msg.file_dumped = 0; - mreset(cached_msg.memdump); - - result = db_fetch_headers (self->msg_idnr, &cached_msg.msg); - if (result == -2) { - dbmail_imap_session_printf(self, "\r\n* BYE internal dbase error\r\n"); - return -1; - } - if (result == -3) { - dbmail_imap_session_printf(self, "\r\n* BYE out of memory\r\n"); + if (self->fi->msgparse_needed) { + rfcsize = _imap_cache_update(self, DBMAIL_MESSAGE_FILTER_FULL); + + if (insert_rfcsize) { + /* insert the rfc822 size into the dbase */ + if (db_set_rfcsize(rfcsize,self->msg_idnr,ud->mailbox.uid) == -1) { + dbmail_imap_session_printf(self,"\r\n* BYE internal dbase error\r\n"); return -1; } - - cached_msg.msg_parsed = 1; - cached_msg.num = self->msg_idnr; - - rfcsize = (cached_msg.msg.rfcheadersize + cached_msg.msg.bodysize + - cached_msg.msg.bodylines); - - if (insert_rfcsize) { - /* insert the rfc822 size into the dbase */ - if (db_set_rfcsize(rfcsize,self->msg_idnr,ud->mailbox.uid) == -1) { - dbmail_imap_session_printf(self,"\r\n* BYE internal dbase error\r\n"); - return -1; - } - - insert_rfcsize = 0; - } - + insert_rfcsize = 0; } } self->fi->isfirstfetchout = 1; if (self->fi->getInternalDate) { - result = db_get_msgdate(ud->mailbox.uid, self->msg_idnr, date); - if (result == -1) { + if (db_get_msgdate(ud->mailbox.uid, self->msg_idnr, date) == -1) { dbmail_imap_session_printf(self, "\r\n* BYE internal dbase error\r\n"); return -1; } - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); - + SEND_SPACE; + dbmail_imap_session_printf(self, "INTERNALDATE \"%s\"", date_sql2imap(date)); } if (self->fi->getMIME_IMB) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); - - tlist = _imap_get_structure(&cached_msg.msg, 1); + + SEND_SPACE; + + tlist = imap_get_structure(GMIME_MESSAGE((cached_msg.dmsg)->content), 1); if (dbmail_imap_session_printf(self, "BODYSTRUCTURE %s", dbmail_imap_plist_as_string(tlist)) == -1) { dbmail_imap_session_printf(self, "\r\n* BYE error fetching body structure\r\n"); return -1; @@ -1383,12 +760,10 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getMIME_IMB_noextension) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); - - tlist = _imap_get_structure(&cached_msg.msg, 0); + + SEND_SPACE; + + tlist = imap_get_structure(GMIME_MESSAGE((cached_msg.dmsg)->content), 0); if (dbmail_imap_session_printf(self, "BODY %s", dbmail_imap_plist_as_string(tlist)) == -1) { dbmail_imap_session_printf(self, "\r\n* BYE error fetching body\r\n"); return -1; @@ -1398,12 +773,10 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getEnvelope) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); - tlist = _imap_get_envelope(&cached_msg.msg.rfcheader); + SEND_SPACE; + + tlist = imap_get_envelope(GMIME_MESSAGE((cached_msg.dmsg)->content)); if (dbmail_imap_session_printf(self, "ENVELOPE %s", dbmail_imap_plist_as_string(tlist)) == -1) { dbmail_imap_session_printf(self, "\r\n* BYE error fetching envelope structure\r\n"); return -1; @@ -1413,13 +786,10 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getRFC822 || self->fi->getRFC822Peek) { - _imap_cache_update(self, DBMAIL_MESSAGE_FILTER_FULL); mseek(cached_msg.memdump, 0, SEEK_SET); - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; dbmail_imap_session_printf(self, "RFC822 {%llu}\r\n", cached_msg.dumpsize); send_data(self->ci->tx, cached_msg.memdump, cached_msg.dumpsize); @@ -1430,21 +800,15 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getSize) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; dbmail_imap_session_printf(self, "RFC822.SIZE %llu", rfcsize); } if (self->fi->getBodyTotal || self->fi->getBodyTotalPeek) { - _imap_cache_update(self, DBMAIL_MESSAGE_FILTER_FULL); - - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; if (dbmail_imap_session_bodyfetch_get_last_octetcnt(self) == 0) { mrewind(cached_msg.memdump); @@ -1469,10 +833,8 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getRFC822Header) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; tmpdumpsize = _imap_cache_update(self,DBMAIL_MESSAGE_FILTER_HEAD); dbmail_imap_session_printf(self, "RFC822.HEADER {%llu}\r\n", tmpdumpsize); @@ -1480,10 +842,8 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getRFC822Text) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; tmpdumpsize = _imap_cache_update(self,DBMAIL_MESSAGE_FILTER_BODY); dbmail_imap_session_printf(self, "RFC822.TEXT {%llu}\r\n", tmpdumpsize); @@ -1522,10 +882,8 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) /* FLAGS ? */ if (self->fi->getFlags) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; int j; int msgflags[IMAP_NFLAGS]; @@ -1545,10 +903,8 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) } if (self->fi->getUID) { - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; dbmail_imap_session_printf(self, "UID %llu", self->msg_idnr); } @@ -1557,20 +913,39 @@ int dbmail_imap_session_fetch_get_items(struct ImapSession *self) g_string_free(tmp,TRUE); return 0; } - -static void _imap_show_body_sections(struct ImapSession *self) { + +static void _imap_show_body_sections(struct ImapSession *self) +{ dbmail_imap_session_bodyfetch_rewind(self); g_list_foreach(self->fi->bodyfetch,(GFunc)_imap_show_body_section, (gpointer)self); dbmail_imap_session_bodyfetch_rewind(self); } -static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data) { +static void imap_cache_send_tmpdump(struct ImapSession *self, body_fetch_t *bodyfetch, u64_t size) +{ + u64_t cnt = 0; + + if (bodyfetch->octetcnt > 0) { + cnt = get_dumpsize(bodyfetch, size); + dbmail_imap_session_printf(self, "]<%llu> {%llu}\r\n", bodyfetch->octetstart, cnt); + mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); + } else { + cnt = size; + dbmail_imap_session_printf(self, "] {%llu}\r\n", size); + mrewind(cached_msg.tmpdump); + } + send_data(self->ci->tx, cached_msg.tmpdump, cnt); +} + - int only_text_from_msgpart = 0; +static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data) +{ long long cnt; u64_t tmpdumpsize; - mime_message_t *msgpart; GList *tlist = NULL; + GString *ts; + GMimeObject *part = NULL; + char *tmp; int k; struct ImapSession *self = (struct ImapSession *)data; @@ -1587,140 +962,75 @@ static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data) { trace(TRACE_DEBUG, "PROTOCOL ERROR"); return 1; } - - msgpart = get_part_by_num(&cached_msg.msg, bodyfetch->partspec); - - if (!msgpart) { - /* if the partspec ends on "1" or "1." the msg body - * of the parent message is to be retrieved - */ - int partspeclen; - partspeclen = strlen(bodyfetch->partspec); - - if ((bodyfetch->partspec[partspeclen - 1] == '1' && - (partspeclen == 1 || bodyfetch->partspec[partspeclen - 2] == '.') - ) - || ((bodyfetch->partspec[partspeclen - 1] == '.' - && bodyfetch->partspec[partspeclen - 2] == '1') - && (partspeclen == 2 || bodyfetch->partspec[partspeclen - 3] == '.')) - ) { - /* ok find the parent of this message */ - /* start value of k is partspeclen-2 'cause we could - have partspec[partspeclen-1] == '.' right at the start - */ - int k; - for (k = partspeclen - 2; k >= 0; k--) - if (bodyfetch->partspec[k] == '.') - break; - - if (k > 0) { - bodyfetch->partspec[k] = '\0'; - msgpart = get_part_by_num(&cached_msg.msg, bodyfetch->partspec); - bodyfetch->partspec[k] = '.'; - } else - msgpart = &cached_msg.msg; - - only_text_from_msgpart = 1; - } - } else { - only_text_from_msgpart = 0; - } + part = imap_get_partspec(GMIME_OBJECT((cached_msg.dmsg)->content), bodyfetch->partspec); } else { if (cached_msg.num == self->msg_idnr) - msgpart = &cached_msg.msg; - else { - /* this will be only the case when only_main_header_parsing == 1 */ - msgpart = &self->headermsg; - } + part = GMIME_OBJECT((cached_msg.dmsg)->content); } - if (self->fi->isfirstfetchout) - self->fi->isfirstfetchout = 0; - else - dbmail_imap_session_printf(self, " "); + + SEND_SPACE; if (! self->fi->noseen) self->fi->setseen = 1; dbmail_imap_session_printf(self, "BODY[%s", bodyfetch->partspec); switch (bodyfetch->itemtype) { - case BFIT_TEXT_SILENT: - if (!msgpart) - dbmail_imap_session_printf(self, "] NIL "); - else { - tmpdumpsize = 0; - - if (only_text_from_msgpart) - tmpdumpsize = _imap_cache_update(self,DBMAIL_MESSAGE_FILTER_BODY); - else - tmpdumpsize = _imap_cache_update(self,DBMAIL_MESSAGE_FILTER_FULL); - - if (bodyfetch->octetcnt > 0) { - cnt = get_dumpsize(bodyfetch, tmpdumpsize); - dbmail_imap_session_printf(self, "]<%llu> {%llu}\r\n", bodyfetch->octetstart, cnt); - mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); - } else { - cnt = tmpdumpsize; - dbmail_imap_session_printf(self, "] {%llu}\r\n", tmpdumpsize); - mrewind(cached_msg.tmpdump); - } - - /* output data */ - send_data(self->ci->tx, cached_msg.tmpdump, cnt); - - } - break; case BFIT_TEXT: - /* dump body text */ dbmail_imap_session_printf(self, "TEXT"); - if (!msgpart) + /* fall through */ + + case BFIT_TEXT_SILENT: + if (!part) dbmail_imap_session_printf(self, "] NIL "); else { - tmpdumpsize = _imap_cache_update(self,DBMAIL_MESSAGE_FILTER_BODY); + tmp = imap_get_logical_part(part,"TEXT"); + tmpdumpsize = _imap_cache_set_dump(tmp,IMAP_CACHE_TMPDUMP); + g_free(tmp); - if (bodyfetch->octetcnt > 0) { - cnt = get_dumpsize(bodyfetch,tmpdumpsize); - dbmail_imap_session_printf(self, "]<%llu> {%llu}\r\n", bodyfetch->octetstart,cnt); - mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); - } else { - cnt = tmpdumpsize; - dbmail_imap_session_printf(self, "] {%llu}\r\n", tmpdumpsize); - mseek(cached_msg.tmpdump, 0, SEEK_SET); - } - /* output data */ - send_data(self->ci->tx, cached_msg.tmpdump, cnt); + if (!tmpdumpsize) + dbmail_imap_session_printf(self, "] NIL\r\n"); + else + imap_cache_send_tmpdump(self,bodyfetch,tmpdumpsize); } break; case BFIT_HEADER: dbmail_imap_session_printf(self, "HEADER"); - if (!msgpart || only_text_from_msgpart) + if (!part) dbmail_imap_session_printf(self, "] NIL\r\n"); else { - tmpdumpsize = rfcheader_dump(cached_msg.tmpdump, &msgpart->rfcheader, self->args, 0, 0); - - if (!tmpdumpsize) { + tmp = imap_get_logical_part(part,"HEADER"); + tmpdumpsize = _imap_cache_set_dump(tmp,IMAP_CACHE_TMPDUMP); + g_free(tmp); + + if (!tmpdumpsize) dbmail_imap_session_printf(self, "] NIL\r\n"); - } else { - if (bodyfetch->octetcnt > 0) { - cnt = get_dumpsize(bodyfetch, tmpdumpsize); - dbmail_imap_session_printf(self, "]<%llu> {%llu}\r\n", bodyfetch->octetstart,cnt); - mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); - } else { - cnt = tmpdumpsize; - dbmail_imap_session_printf(self, "] {%llu}\r\n", tmpdumpsize); - mseek(cached_msg.tmpdump,0,SEEK_SET); - } - /* output data */ - send_data(self->ci->tx,cached_msg.tmpdump,cnt); - - } + else + imap_cache_send_tmpdump(self,bodyfetch,tmpdumpsize); } break; + case BFIT_MIME: + dbmail_imap_session_printf(self, "MIME] "); + + if (!part) + dbmail_imap_session_printf(self, "NIL\r\n"); + else { + tmp = imap_get_logical_part(part,"MIME"); + tmpdumpsize = _imap_cache_set_dump(tmp,IMAP_CACHE_TMPDUMP); + g_free(tmp); + + if (!tmpdumpsize) + dbmail_imap_session_printf(self, "NIL\r\n"); + else + imap_cache_send_tmpdump(self,bodyfetch,tmpdumpsize); + } + + break; + case BFIT_HEADER_FIELDS: - tlist = NULL; for (k = 0; k < bodyfetch->argcnt; k++) tlist = g_list_append(tlist, g_strdup(self->args[k + bodyfetch->argstart])); @@ -1728,31 +1038,52 @@ static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data) { dbmail_imap_session_printf(self,"HEADER.FIELDS %s", dbmail_imap_plist_as_string(tlist)); dbmail_imap_session_printf(self, "] "); g_list_foreach(tlist, (GFunc)g_free, NULL); + g_list_free(tlist); + tlist = NULL; - if (!msgpart || only_text_from_msgpart) + if (!part) dbmail_imap_session_printf(self, "NIL\r\n"); else { - tmpdumpsize = rfcheader_dump(cached_msg.tmpdump, - &msgpart->rfcheader, &self->args[bodyfetch->argstart], - bodyfetch->argcnt, 1); - - if (!tmpdumpsize) { + tmpdumpsize=0; + for (k = 0; k < bodyfetch->argcnt; k++) { + if ((tmp = (char *)g_mime_object_get_header(part, self->args[k + bodyfetch->argstart]))) + tlist = g_list_append_printf(tlist,"%s: %s", + self->args[k + bodyfetch->argstart], tmp); + } + tlist = g_list_append_printf(tlist,"\r\n"); + + if (!g_list_length(tlist) > 1) { dbmail_imap_session_printf(self, "NIL\r\n"); } else { + ts = g_list_join(tlist,"\r\n"); + if (bodyfetch->octetcnt > 0) { - cnt = get_dumpsize(bodyfetch, tmpdumpsize); - dbmail_imap_session_printf(self, "<%llu> {%llu}\r\n", bodyfetch->octetstart, cnt); - mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); + + if (bodyfetch->octetstart > 0 && bodyfetch->octetstart < ts->len) + ts = g_string_erase(ts, 0, bodyfetch->octetstart); + + if (ts->len > bodyfetch->octetcnt) + ts = g_string_truncate(ts, bodyfetch->octetcnt); + + tmp = get_crlf_encoded(ts->str); + cnt = strlen(tmp); + + dbmail_imap_session_printf(self, "<%llu> {%llu}\r\n%s", + bodyfetch->octetstart, + cnt, + tmp); } else { - cnt = tmpdumpsize; - dbmail_imap_session_printf(self, "{%llu}\r\n", tmpdumpsize); - mseek(cached_msg.tmpdump, 0, SEEK_SET); + tmp = get_crlf_encoded(ts->str); + cnt = strlen(tmp); + dbmail_imap_session_printf(self, "{%llu}\r\n%s", cnt, tmp); } - - /* output data */ - send_data(self->ci->tx,cached_msg.tmpdump,cnt); - + g_string_free(ts,TRUE); + g_free(tmp); } + + g_list_foreach(tlist, (GFunc)g_free, NULL); + g_list_free(tlist); + tlist = NULL; } break; case BFIT_HEADER_FIELDS_NOT: @@ -1764,57 +1095,44 @@ static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data) { dbmail_imap_session_printf(self, "HEADER.FIELDS.NOT %s", dbmail_imap_plist_as_string(tlist)); dbmail_imap_session_printf(self, "] "); g_list_foreach(tlist,(GFunc)g_free,NULL); + g_list_free(tlist); - if (!msgpart || only_text_from_msgpart) + if (!part) dbmail_imap_session_printf(self, "NIL\r\n"); else { - tmpdumpsize = rfcheader_dump(cached_msg.tmpdump, - &msgpart->rfcheader, &self->args[bodyfetch->argstart], - bodyfetch->argcnt, 0); - - if (!tmpdumpsize) { - dbmail_imap_session_printf(self, "NIL\r\n"); - } else { - if (bodyfetch->octetcnt > 0) { - cnt = get_dumpsize(bodyfetch, tmpdumpsize); - dbmail_imap_session_printf(self, "<%llu> {%llu}\r\n", bodyfetch->octetstart, cnt); - mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); - } else { - cnt = tmpdumpsize; - dbmail_imap_session_printf(self, "{%llu}\r\n", tmpdumpsize); - mseek(cached_msg.tmpdump, 0, SEEK_SET); - } - /* output data */ - send_data(self->ci->tx, cached_msg.tmpdump, cnt); + for (k = 0; k < bodyfetch->argcnt; k++) { + g_mime_object_remove_header(part, self->args[k + bodyfetch->argstart]); } - } - break; - case BFIT_MIME: - dbmail_imap_session_printf(self, "MIME] "); - - if (!msgpart) - dbmail_imap_session_printf(self, "NIL\r\n"); - else { - tmpdumpsize = mimeheader_dump(cached_msg.tmpdump, &msgpart->mimeheader); + ts = g_string_new(g_mime_object_get_headers(part)); - if (!tmpdumpsize) { + if (! ts->len > 0) { dbmail_imap_session_printf(self, "NIL\r\n"); } else { if (bodyfetch->octetcnt > 0) { - cnt = get_dumpsize(bodyfetch, tmpdumpsize); - dbmail_imap_session_printf(self, "<%llu> {%llu}\r\n", bodyfetch->octetstart, cnt); - mseek(cached_msg.tmpdump, bodyfetch->octetstart, SEEK_SET); + + if (bodyfetch->octetstart > 0 && bodyfetch->octetstart < ts->len) + ts = g_string_truncate(ts,bodyfetch->octetstart); + + if (bodyfetch->octetcnt < ts->len) + ts = g_string_erase(ts,0,bodyfetch->octetcnt); + + tmp = get_crlf_encoded(ts->str); + cnt = strlen(tmp); + + dbmail_imap_session_printf(self, "<%llu> {%llu}\r\n%s", + bodyfetch->octetstart, cnt, tmp); + + } else { - cnt = tmpdumpsize; - dbmail_imap_session_printf(self, "{%llu}\r\n", tmpdumpsize); - mseek(cached_msg.tmpdump, 0, SEEK_SET); + tmp = get_crlf_encoded(ts->str); + cnt = strlen(tmp); + + dbmail_imap_session_printf(self, "{%llu}\r\n%s", cnt, tmp); } - - /* output data */ - send_data(self->ci->tx, cached_msg.tmpdump, cnt); + g_free(tmp); } + g_string_free(ts,TRUE); } - break; default: dbmail_imap_session_printf(self, "\r\n* BYE internal server error\r\n"); @@ -1875,36 +1193,62 @@ int check_state_and_args(struct ImapSession * self, const char *command, int min /* succes */ return 1; } - + int dbmail_imap_session_printf(struct ImapSession * self, char * message, ...) { - int maxlen=100; - int result = 0; - gchar *re = g_new0(gchar, maxlen+1); - va_list ap; - - FILE * fd = self->ci->tx; - int len; - va_start(ap, message); - if (feof(fd) || (len = vfprintf(fd,message,ap)) < 0 || fflush(fd) < 0) { - va_end(ap); - return -1; - } - va_end(ap); - - va_start(ap, message); - result = vsnprintf(re,maxlen,message,ap); - va_end(ap); - - if (result < maxlen) - trace(TRACE_DEBUG,"RESPONSE: [%s]", re); - else - trace(TRACE_DEBUG,"RESPONSE: [%s...]", re); - g_free(re); - - return len; + va_list ap; + int len; + FILE * fd; + int maxlen=100; + int result = 0; + GMimeStream *ostream, *fstream; + GMimeFilter *filter; + + gchar *re = g_new0(gchar, maxlen+1); + gchar *ln = g_new0(gchar, MAX_LINESIZE+1); + + va_start(ap, message); + result = vsnprintf(ln,MAX_LINESIZE,message,ap); + va_end(ap); + + if (result < 0) + return -1; + + if ((result = snprintf(re,maxlen,ln))<0) + return -1; + + fd = self->ci->tx; + + if (feof(fd) || fflush(fd) < 0) { + trace(TRACE_FATAL, "%s,%s: client socket closed", __FILE__, __func__); + return -1; + } + + ostream = g_mime_stream_fs_new(dup(fileno(fd))); + fstream = g_mime_stream_filter_new_with_stream(ostream); + filter = g_mime_filter_crlf_new(GMIME_FILTER_CRLF_ENCODE,GMIME_FILTER_CRLF_MODE_CRLF_ONLY); + g_mime_stream_filter_add((GMimeStreamFilter *) fstream, filter); + len = g_mime_stream_write_string(fstream,ln); + + if (len < 0) { + trace(TRACE_FATAL, "%s,%s: write to client socket failed", __FILE__, __func__); + return -1; + } + + g_free(ln); + g_object_unref(filter); + g_object_unref(ostream); + g_object_unref(fstream); + + if (result < maxlen) + trace(TRACE_DEBUG,"RESPONSE: [%s]", re); + else + trace(TRACE_DEBUG,"RESPONSE: [%s...]", re); + g_free(re); + + return len; } - + int dbmail_imap_session_readln(struct ImapSession * self, char * buffer) { memset(buffer, 0, MAX_LINESIZE); @@ -2469,7 +1813,6 @@ char **build_args_array_ext(const char *originalString, clientinfo_t * ci) if (paridx < 0) { /* error in parenthesis structure */ - g_strfreev(the_args); return NULL; } diff --git a/dbmail-imapsession.h b/dbmail-imapsession.h index 96fcd34e..390855ec 100644 --- a/dbmail-imapsession.h +++ b/dbmail-imapsession.h @@ -2,13 +2,7 @@ #ifndef _DBMAIL_COMMANDCHANNEL_H #define _DBMAIL_COMMANDCHANNEL_H -#include "dbmailtypes.h" -#include "acl.h" -#include "misc.h" -#include "auth.h" -#include "imap4.h" -#include "glib.h" -#include "dbmail-message.h" +#include "dbmail.h" /* ImapSession definition */ struct ImapSession { diff --git a/dbmail-message.c b/dbmail-message.c index c0b1df35..17825cbe 100644 --- a/dbmail-message.c +++ b/dbmail-message.c @@ -25,29 +25,8 @@ * implements DbmailMessage object */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <sys/types.h> -#include <time.h> - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "dbmail.h" -#include "dbmail-message.h" -#include "db.h" -#include "auth.h" -#include "misc.h" -#include "pipe.h" - -#ifdef SIEVE -#include "sortsieve.h" -#endif -#include "sort.h" -#include "forward.h" + extern db_param_t _db_params; #define DBPFX _db_params.pfx @@ -278,7 +257,7 @@ static void _register_header(const char *header, const char *value, gpointer use g_relation_insert((GRelation *)user_data, (gpointer)header, (gpointer)value); } -static gchar * _get_crlf_encoded(gchar *string) +gchar * get_crlf_encoded(gchar *string) { GMimeStream *ostream, *fstream; GMimeFilter *filter; @@ -348,43 +327,38 @@ gchar * dbmail_message_get_header(struct DbmailMessage *self, const char *header } /* dump message(parts) to char ptrs */ -gchar * dbmail_message_to_string(struct DbmailMessage *self, gboolean crlf) +gchar * dbmail_message_to_string(struct DbmailMessage *self) { - gchar *msg, *encoded; - - assert(self->content); - msg = g_mime_object_to_string(GMIME_OBJECT(self->content)); - - if (! crlf) - return msg; - - encoded = _get_crlf_encoded(msg); - g_free(msg); - return encoded; + return g_mime_object_to_string(GMIME_OBJECT(self->content)); } -gchar * dbmail_message_hdrs_to_string(struct DbmailMessage *self, gboolean crlf) +gchar * dbmail_message_hdrs_to_string(struct DbmailMessage *self) { - char *hdrs, *encoded; - assert(self->headers); + gchar *h; + GString *hs; + + h = g_mime_object_get_headers(GMIME_OBJECT(self->content)); + hs = g_string_new(h); + g_free(h); + + /* append newline */ + hs = g_string_append_c(hs, '\n'); + h = hs->str; + g_string_free(hs,FALSE); + return h; - hdrs = g_mime_object_get_headers(GMIME_OBJECT(self->content)); - if (! crlf) - return hdrs; - encoded = _get_crlf_encoded(hdrs); - g_free(hdrs); - return encoded; } -gchar * dbmail_message_body_to_string(struct DbmailMessage *self, gboolean crlf) +gchar * dbmail_message_body_to_string(struct DbmailMessage *self) { char *s, *b; + size_t h; GString *t; - assert(self->content); - b = dbmail_message_to_string(self, crlf); + b = dbmail_message_to_string(self); t = g_string_new(b); g_free(b); - t = g_string_erase(t,0,dbmail_message_get_hdrs_size(self, crlf)); + h = dbmail_message_get_hdrs_size(self,FALSE); + t = g_string_erase(t,0,h); s = t->str; g_string_free(t,FALSE); @@ -399,25 +373,49 @@ gchar * dbmail_message_body_to_string(struct DbmailMessage *self, gboolean crlf) */ size_t dbmail_message_get_size(struct DbmailMessage *self, gboolean crlf) { - char *s; size_t r; - s = dbmail_message_to_string(self, crlf); - r = strlen(s); + char *s, *t; size_t r; + s = dbmail_message_to_string(self); + + if (crlf) { + t = get_crlf_encoded(s); + r = strlen(t); + g_free(t); + } else { + r = strlen(s); + } + g_free(s); return r; } size_t dbmail_message_get_hdrs_size(struct DbmailMessage *self, gboolean crlf) { - char *s; size_t r; - s = dbmail_message_hdrs_to_string(self,crlf); - r = strlen(s); + char *s, *t; size_t r; + s = dbmail_message_hdrs_to_string(self); + + if (crlf) { + t = get_crlf_encoded(s); + r = strlen(t); + g_free(t); + } else { + r = strlen(s); + } + g_free(s); return r; } size_t dbmail_message_get_body_size(struct DbmailMessage *self, gboolean crlf) { - char *s; size_t r; - s = dbmail_message_body_to_string(self,crlf); - r = strlen(s); + char *s, *t; size_t r; + s = dbmail_message_body_to_string(self); + + if (crlf) { + t = get_crlf_encoded(s); + r = strlen(t); + g_free(t); + } else { + r = strlen(s); + } + g_free(s); return r; } @@ -556,8 +554,8 @@ int dbmail_message_store(struct DbmailMessage *self) if(_message_insert(self, user_idnr, DBMAIL_TEMPMBOX, unique_id) < 0) return -1; - hdrs = dbmail_message_hdrs_to_string(self, FALSE); - body = dbmail_message_body_to_string(self, FALSE); + hdrs = dbmail_message_hdrs_to_string(self); + body = dbmail_message_body_to_string(self); hdrs_size = (u64_t)dbmail_message_get_hdrs_size(self, FALSE); body_size = (u64_t)dbmail_message_get_body_size(self, FALSE); rfcsize = (u64_t)dbmail_message_get_rfcsize(self); @@ -957,8 +955,11 @@ dsn_class_t sort_and_deliver(struct DbmailMessage *message, u64_t useridnr, cons trace(TRACE_MESSAGE, "%s, %s: message id=%llu, size=%d is inserted", __FILE__, __func__, newmsgidnr, msgsize); + message->id = newmsgidnr; + return DSN_CLASS_OK; } } } + diff --git a/dbmail-message.h b/dbmail-message.h index 3b04d29f..dcd4dcb9 100644 --- a/dbmail-message.h +++ b/dbmail-message.h @@ -28,14 +28,7 @@ #define _DBMAIL_MESSAGE_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmailtypes.h" -#include "dsn.h" -#include <gmime/gmime.h> -#include <assert.h> +#include "dbmail.h" #define MSGBUF_FORCE_UPDATE -1 @@ -108,9 +101,9 @@ gchar * dbmail_message_get_internal_date(struct DbmailMessage *self); int dbmail_message_set_class(struct DbmailMessage *self, int klass); int dbmail_message_get_class(struct DbmailMessage *self); -gchar * dbmail_message_to_string(struct DbmailMessage *self, gboolean crlf); -gchar * dbmail_message_hdrs_to_string(struct DbmailMessage *self, gboolean crlf); -gchar * dbmail_message_body_to_string(struct DbmailMessage *self, gboolean crlf); +gchar * dbmail_message_to_string(struct DbmailMessage *self); +gchar * dbmail_message_hdrs_to_string(struct DbmailMessage *self); +gchar * dbmail_message_body_to_string(struct DbmailMessage *self); size_t dbmail_message_get_size(struct DbmailMessage *self, gboolean crlf); @@ -119,6 +112,7 @@ size_t dbmail_message_get_size(struct DbmailMessage *self, gboolean crlf); size_t dbmail_message_get_hdrs_size(struct DbmailMessage *self, gboolean crlf); size_t dbmail_message_get_body_size(struct DbmailMessage *self, gboolean crlf); +gchar * get_crlf_encoded(gchar *string); /* * manipulate the actual message content */ @@ -134,6 +128,8 @@ void dbmail_message_cache_datefield(struct DbmailMessage *self); void dbmail_message_cache_subjectfield(struct DbmailMessage *self); void dbmail_message_cache_referencesfield(struct DbmailMessage *self); +GList * dbmail_message_get_structure(struct DbmailMessage *self, gboolean extension); +GList * dbmail_message_get_envelope(struct DbmailMessage *self); /* * destructor */ diff --git a/dbmail-user.c b/dbmail-user.c index 129501bd..06a79de3 100644 --- a/dbmail-user.c +++ b/dbmail-user.c @@ -21,31 +21,7 @@ * This is the dbmail-user program * It makes adding users easier */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmail-user.h" -#include "auth.h" -#include <stdio.h> -#include <termios.h> -#include <stdlib.h> -#include <string.h> #include "dbmail.h" -#include "list.h" -#include "debug.h" -#include "db.h" -#include "misc.h" -#include <time.h> -#include <stdarg.h> -#include <sys/types.h> -#include <unistd.h> -#ifdef HAVE_CRYPT_H -#include <crypt.h> -#endif -#include "dbmd5.h" - - extern char *configFile; diff --git a/dbmail-user.h b/dbmail-user.h index a86d8b5a..638609bd 100644 --- a/dbmail-user.h +++ b/dbmail-user.h @@ -19,12 +19,10 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#ifndef _DBMAIL_USER_H +#define _DBMAIL_USER_H #include "dbmail.h" -#include "dbmailtypes.h" #define qprintf(fmt, args...) ((quiet||reallyquiet) ? 0 : printf(fmt, ##args) ) #define qerrorf(fmt, args...) (reallyquiet ? 0 : fprintf(stderr, fmt, ##args) ) @@ -86,3 +84,5 @@ int do_forwards(const char *alias, const u64_t clientid, /* Helper functions */ int is_valid(const char * const str); u64_t strtomaxmail(const char * const str); + +#endif @@ -30,25 +30,99 @@ #ifdef HAVE_CONFIG_H #include "config.h" #else -#define VERSION "2.0" +#define VERSION "2.1" #define PACKAGE "dbmail" #endif + +#include <assert.h> +#include <arpa/inet.h> +#include <ctype.h> +#include <errno.h> +#include <fcntl.h> +#include <fnmatch.h> +#include <gmime/gmime.h> #include <glib.h> -#include "list.h" - -/* Define several macros for GCC specific attributes. - * Although the __attribute__ macro can be easily defined - * to nothing, these macros make them a little prettier. - * */ -#ifdef __GNUC__ -#define UNUSED __attribute__((__unused__)) -#define PRINTF_ARGS(X, Y) __attribute__((format(printf, X, Y))) -#else -#define UNUSED -#define PRINTF_ARGS(X, Y) +#include <grp.h> +#include <limits.h> +#include <netinet/in.h> +#include <netdb.h> +#include <pwd.h> +#include <signal.h> +#include <syslog.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <sysexits.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <time.h> +#include <termios.h> +#include <unistd.h> + +#include "dbmailtypes.h" +#include "debug.h" +#include "dsn.h" +#include "acl.h" +#include "misc.h" +#include "main.h" +#include "pipe.h" +#include "db.h" +#include "auth.h" +#include "imap4.h" +#include "imapcommands.h" +#include "memblock.h" +#include "mime.h" +#include "dbmsgbuf.h" +#include "rfcmsg.h" +#include "pidfile.h" +#include "sort.h" +#include "forward.h" +#include "dbmd5.h" +#include "md5.h" +#include "server.h" +#include "serverchild.h" +#include "pool.h" +#include "pop3.h" +#include "quota.h" +#include "lmtp.h" +#include "lib/iniparser-2.14/src/iniparser.h" + +#include "dm_cidr.h" +#include "dm_imaputil.h" +#include "dm_search.h" +#include "dm_getopt.h" + +#ifdef SIEVE +#include "sortsieve.h" +#include "sievecmd.h" +#include "sort/sortsieve.h" +#include "timsieve.h" #endif +#ifdef HAVE_CRYPT_H +#include <crypt.h> +#endif + +#ifdef HAVE_ENDIAN_H +#include <endian.h> +#endif + +#include "dbmail-message.h" +#include "dbmail-user.h" +#include "dbmail-mailbox.h" +#include "dbmail-imapsession.h" + + #define GETCONFIGVALUE(key, sect, var) \ config_get_value(key, sect, var); \ @@ -62,8 +136,6 @@ #define CONFIG_ERROR_LEVEL TRACE_WARNING -/** string length of configuration values */ -#define FIELDSIZE 1024 #define COPYRIGHT "(c) 1999-2004 IC&S, The Netherlands" /** default directory and extension for pidfiles */ #define DEFAULT_PID_DIR "/var/run/" @@ -88,58 +160,6 @@ #define MATCH(x,y) strcasecmp(x,y)==0 -typedef enum { - DM_EQUERY = -1, - DM_SUCCESS = 0, - DM_EGENERAL = 1 -} DbmailErrorCodes; - -/** status fields for messages */ -typedef enum { - MESSAGE_STATUS_NEW = 0, - MESSAGE_STATUS_SEEN = 1, - MESSAGE_STATUS_DELETE = 2, - MESSAGE_STATUS_PURGE = 3, - MESSAGE_STATUS_UNUSED = 4, - MESSAGE_STATUS_INSERT = 5, - MESSAGE_STATUS_ERROR = 6 -} MessageStatus_t; - -/** field_t is used for storing configuration values */ -typedef char field_t[FIELDSIZE]; - -/** size of a timestring_t field */ -#define TIMESTRING_SIZE 30 -/** timestring_t is used for holding timestring */ -typedef char timestring_t[TIMESTRING_SIZE]; - -/** parameters for the database connection */ -typedef struct { - field_t host; - /**< hostname or ip address of database server */ - field_t user; - /**< username to connect with */ - field_t pass; - /**< password of user */ - field_t db;/**< name of database to connect with */ - unsigned int port; - /**< port number of database server */ - field_t sock; - /**< path to local unix socket (local connection) */ - field_t pfx; - /**< prefix for tables e.g. dbmail_ */ - unsigned int serverid; /* unique id for dbmail instance used in clusters */ - -} db_param_t; - -/** configuration items */ -typedef struct { - field_t name; - /**< name of configuration item */ - field_t value; - /**< value of configuration item */ -} item_t; - /** * \brief read configuration from filename * \param cfilename name of configuration file @@ -181,4 +201,5 @@ void GetDBParams(db_param_t * db_params); void SetTraceLevel(const char *service_name); +void pidfile_create(const char *pidFile, pid_t pid); #endif diff --git a/dbmailtypes.h b/dbmailtypes.h index 2f88358c..ae5391c9 100644 --- a/dbmailtypes.h +++ b/dbmailtypes.h @@ -22,8 +22,9 @@ /** * \file dbmailtypes.h * - * a set of data type definitions used at various - * places within the dbmail package + * all data type definitions used within the dbmail package should + * be declared here. + * */ #ifndef _DBMAILTYPES_H @@ -34,7 +35,6 @@ #endif #include <stdio.h> -#include "dbmail.h" #include "memblock.h" #include "list.h" @@ -46,13 +46,73 @@ #define UID_SIZE 70 #define IPNUM_LEN 32 +#define IPLEN 32 +#define BACKLOG 16 + #define DM_SOCKADDR_LEN 108 #define DM_USERNAME_LEN 100 +/** string length of configuration values */ +#define FIELDSIZE 1024 + /** use 64-bit unsigned integers as common data type */ typedef unsigned long long u64_t; +typedef enum { + DM_EQUERY = -1, + DM_SUCCESS = 0, + DM_EGENERAL = 1 +} DbmailErrorCodes; + +/** status fields for messages */ +typedef enum { + MESSAGE_STATUS_NEW = 0, + MESSAGE_STATUS_SEEN = 1, + MESSAGE_STATUS_DELETE = 2, + MESSAGE_STATUS_PURGE = 3, + MESSAGE_STATUS_UNUSED = 4, + MESSAGE_STATUS_INSERT = 5, + MESSAGE_STATUS_ERROR = 6 +} MessageStatus_t; + +/** field_t is used for storing configuration values */ +typedef char field_t[FIELDSIZE]; + +/** size of a timestring_t field */ +#define TIMESTRING_SIZE 30 + +/** timestring_t is used for holding timestring */ +typedef char timestring_t[TIMESTRING_SIZE]; + +/** parameters for the database connection */ +typedef struct { + field_t host; + /**< hostname or ip address of database server */ + field_t user; + /**< username to connect with */ + field_t pass; + /**< password of user */ + field_t db;/**< name of database to connect with */ + unsigned int port; + /**< port number of database server */ + field_t sock; + /**< path to local unix socket (local connection) */ + field_t pfx; + /**< prefix for tables e.g. dbmail_ */ + unsigned int serverid; /* unique id for dbmail instance used in clusters */ + +} db_param_t; + +/** configuration items */ +typedef struct { + field_t name; + /**< name of configuration item */ + field_t value; + /**< value of configuration item */ +} item_t; + + typedef struct { FILE *tx, *rx; @@ -200,6 +260,24 @@ enum BODY_FETCH_ITEM_TYPES { /* max length of number/dots part specifier */ #define IMAP_MAX_PARTSPEC_LEN 100 + +typedef struct { + int listenSocket; + int startChildren; + int minSpareChildren; + int maxSpareChildren; + int maxChildren; + int childMaxConnect; + int timeout; + char ip[IPLEN]; + int port; + int resolveIP; + char *timeoutMsg; + field_t serverUser, serverGroup; + field_t socket; + int (*ClientHandler) (clientinfo_t *); +} serverConfig_t; + /* * (imap) mailbox data type */ @@ -255,31 +333,30 @@ typedef struct { /** - * RFC822/MIME message data type - */ +* RFC822/MIME message data type +*/ typedef struct { - struct dm_list mimeheader; /**< the MIME header of this part (if present) */ - struct dm_list rfcheader; /**< RFC822 header of this part (if present) */ - struct dm_list children; /**< the children (multipart msg) */ - - int message_has_errors; /**< if set the content-type is meaningless */ - - db_pos_t bodystart, bodyend; /**< the body of this part */ - - u64_t bodysize; /**< size of message body */ - u64_t bodylines; /**< number of lines in message body */ - u64_t rfcheadersize; /**< size of rfc header */ - u64_t rfcheaderlines; /** number of lines in rfc header */ - u64_t mimerfclines; /**< the total number of lines (only specified in - case of a MIME msg containing an RFC822 msg) */ -} mime_message_t; - + struct dm_list mimeheader; /**< the MIME header of this part (if present) */ + struct dm_list rfcheader; /**< RFC822 header of this part (if present) */ + struct dm_list children; /**< the children (multipart msg) */ + int message_has_errors; /**< if set the content-type is meaningless */ + db_pos_t bodystart, bodyend; /**< the body of this part */ + + u64_t bodysize; /**< size of message body */ + u64_t bodylines; /**< number of lines in message body */ + u64_t rfcheadersize; /**< size of rfc header */ + u64_t rfcheaderlines; /** number of lines in rfc header */ + u64_t mimerfclines; /**< the total number of lines (only specified in + case of a MIME msg containing an RFC822 msg) */ +} mime_message_t; + /* * simple cache mechanism */ typedef struct { + struct DbmailMessage *dmsg; mime_message_t msg; MEM *memdump, *tmpdump; u64_t num; @@ -325,4 +402,31 @@ typedef struct { int free_action : 1; // a } sievefree_t; + +#define SA_KEEP 1 +#define SA_DISCARD 2 +#define SA_REDIRECT 3 +#define SA_REJECT 4 +#define SA_FILEINTO 5 + +typedef struct sort_action { + int method; + char *destination; + char *message; +} sort_action_t; + +typedef enum { + ACL_RIGHT_LOOKUP, + ACL_RIGHT_READ, + ACL_RIGHT_SEEN, + ACL_RIGHT_WRITE, + ACL_RIGHT_INSERT, + ACL_RIGHT_POST, + ACL_RIGHT_CREATE, + ACL_RIGHT_DELETE, + ACL_RIGHT_ADMINISTER, + ACL_RIGHT_NONE +} ACLRight_t; + + #endif @@ -21,17 +21,7 @@ * * Functions to create md5 hash from buf */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "dbmd5.h" -#include "md5.h" -#include "debug.h" +#include "dbmail.h" unsigned char *makemd5(const char * const buf) { @@ -24,10 +24,6 @@ #ifndef _DBMD5_H #define _DBMD5_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - /** * \brief calculate md5-hash of a string * \param buf input string @@ -25,23 +25,13 @@ * implement msgbuf functions prototyped in dbmsgbuf.h */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmsgbuf.h" -#include "db.h" -#include "dbmail-message.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> +#include "dbmail.h" #define MSGBUF_WINDOWSIZE (128ull*1024ull) extern db_param_t _db_params; #define DBPFX _db_params.pfx -static unsigned _msgrow_idx = 0; static int _msg_fetch_inited = 0; /* for issuing queries to the backend */ @@ -50,7 +40,6 @@ char query[DEF_QUERYSIZE]; /** * CONDITIONS FOR MSGBUF */ -static u64_t rowlength = 0; /**< length of current row*/ static u64_t rowpos = 0; /**< current position in row */ static db_pos_t zeropos; /**< absolute position (block/offset) of msgbuf_buf[0]*/ @@ -65,143 +54,37 @@ struct DbmailMessage * db_init_fetch(u64_t msg_idnr, int filter) result = db_get_physmessage_id(msg_idnr, &physid); if (result != DM_SUCCESS) return NULL; - - /* retrieve message */ msg = dbmail_message_new(); - return dbmail_message_retrieve(msg, physid, filter); } -int db_init_fetch_messageblks(u64_t msg_idnr, int filter) +struct DbmailMessage * db_init_fetch_message(u64_t msg_idnr, int filter) { struct DbmailMessage *msg; + char *buf; msg = db_init_fetch(msg_idnr, filter); if (! msg) - return DM_EGENERAL; + return NULL; - /* set globals */ - msgbuf_buf = dbmail_message_to_string(msg, TRUE); + /* set globals: msgbuf contains a crlf decoded version of the message at hand */ + buf = dbmail_message_to_string(msg); + msgbuf_buf = buf; + msgbuf_idx = 0; msgbuf_buflen = strlen(msgbuf_buf); db_store_msgbuf_result(); /* done */ - dbmail_message_free(msg); - return 1; - + return msg; } -int db_update_msgbuf(int minlen) +int db_update_msgbuf(int minlen UNUSED) { /* use the former msgbuf_result */ db_use_msgbuf_result(); - - if (_msgrow_idx >= db_num_rows()) { - db_store_msgbuf_result(); - return 0; /* no more */ - } - - if (msgbuf_idx > msgbuf_buflen) { - db_store_msgbuf_result(); - return -1; /* error, msgbuf_idx should be within buf */ - } - - if (minlen > 0 && ((int) (msgbuf_buflen - msgbuf_idx)) > minlen) { - db_store_msgbuf_result(); - return 1; /* ok, need no update */ - } - - if (msgbuf_idx == 0) { - db_store_msgbuf_result(); - return 1; /* update no use, buffer would not change */ - } - - - trace(TRACE_DEBUG, - "%s,%s: update msgbuf_buf updating %llu, %llu, %llu, %llu", - __FILE__, __func__, MSGBUF_WINDOWSIZE, - msgbuf_buflen, rowlength, rowpos); - - /* move buf to make msgbuf_idx 0 */ - memmove(msgbuf_buf, &msgbuf_buf[msgbuf_idx], - (msgbuf_buflen - msgbuf_idx)); - if (msgbuf_idx > (msgbuf_buflen - rowpos)) { - zeropos.block++; - zeropos.pos = (msgbuf_idx - ((msgbuf_buflen) - rowpos)); - } else { - zeropos.pos += msgbuf_idx; - } - - msgbuf_buflen -= msgbuf_idx; - msgbuf_idx = 0; - - if ((rowlength - rowpos) >= (MSGBUF_WINDOWSIZE - msgbuf_buflen)) { - trace(TRACE_DEBUG, "%s,%s update msgbuf non-entire fit", - __FILE__, __func__); - - /* rest of row does not fit entirely in buf */ - /* FIXME: this will explode is db_get_result returns NULL. */ - strncpy(&msgbuf_buf[msgbuf_buflen], - &((db_get_result(_msgrow_idx, 0))[rowpos]), - MSGBUF_WINDOWSIZE - msgbuf_buflen); - rowpos += (MSGBUF_WINDOWSIZE - msgbuf_buflen - 1); - - msgbuf_buflen = MSGBUF_WINDOWSIZE - 1; - msgbuf_buf[msgbuf_buflen] = '\0'; - - db_store_msgbuf_result(); - return 1; - } - - trace(TRACE_DEBUG, "%s,%s: update msgbuf: entire fit", - __FILE__, __func__); - - /* FIXME: this will explode is db_get_result returns NULL. */ - strncpy(&msgbuf_buf[msgbuf_buflen], - &((db_get_result(_msgrow_idx, 0))[rowpos]), - (rowlength - rowpos)); - msgbuf_buflen += (rowlength - rowpos); - msgbuf_buf[msgbuf_buflen] = '\0'; - rowpos = rowlength; - - /* try to fetch a new row */ - _msgrow_idx++; - if (_msgrow_idx >= db_num_rows()) { - trace(TRACE_DEBUG, "%s,%s update msgbuf succes NOMORE", - __FILE__, __func__); - db_store_msgbuf_result(); - return 0; - } - - rowlength = db_get_length(_msgrow_idx, 0); - rowpos = 0; - - trace(TRACE_DEBUG, "%s,%s: update msgbuf, got new block, " - "trying to place data", __FILE__, __func__); - - /* FIXME: this will explode is db_get_result returns NULL. */ - strncpy(&msgbuf_buf[msgbuf_buflen], db_get_result(_msgrow_idx, 0), - MSGBUF_WINDOWSIZE - msgbuf_buflen - 1); - - if (rowlength <= MSGBUF_WINDOWSIZE - msgbuf_buflen - 1) { - /* 2nd block fits entirely */ - trace(TRACE_DEBUG, - "update msgbuf: new block fits entirely\n"); - - rowpos = rowlength; - msgbuf_buflen += rowlength; - } else { - rowpos = MSGBUF_WINDOWSIZE - (msgbuf_buflen + 1); - msgbuf_buflen = MSGBUF_WINDOWSIZE - 1; - } - - msgbuf_buf[msgbuf_buflen] = '\0'; /* add NULL */ - - trace(TRACE_DEBUG, "%s,%s: update msgbuf succes", __FILE__, - __func__); db_store_msgbuf_result(); return 1; } @@ -30,13 +30,7 @@ #ifndef _DBMSGBUF_H #define _DBMSGBUF_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmailtypes.h" -#include "dbmail-message.h" -#include "memblock.h" +#include "dbmail.h" #define MSGBUF_FORCE_UPDATE -1 @@ -45,8 +39,6 @@ u64_t msgbuf_idx;/**< index within msgbuf, 0 <= msgidx < buflen */ u64_t msgbuf_buflen;/**< current buffer length: msgbuf[buflen] == '\\0' */ struct DbmailMessage * db_init_fetch(u64_t msg_idnr, int filter); -int db_init_fetch_messageblks(u64_t msg_idnr, int filter); - /** * \brief initialises a message fetch @@ -56,7 +48,7 @@ int db_init_fetch_messageblks(u64_t msg_idnr, int filter); * - 0 if already inited (sic) before * - 1 on success */ -#define db_init_fetch_message(x) db_init_fetch_messageblks(x, DBMAIL_MESSAGE_FILTER_FULL) +struct DbmailMessage * db_init_fetch_message(u64_t msg_idnr, int filter); /** * \brief initialises a message headers fetch @@ -66,7 +58,7 @@ int db_init_fetch_messageblks(u64_t msg_idnr, int filter); * - 0 if already inited (sic) before * - 1 on success */ -#define db_init_fetch_headers(x) db_init_fetch_messageblks(x,DBMAIL_MESSAGE_FILTER_HEAD) +#define db_init_fetch_headers(x) db_init_fetch_message(x,DBMAIL_MESSAGE_FILTER_HEAD) /** * \brief update msgbuf diff --git a/debian/changelog b/debian/changelog index b6477076..1776d0ea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +dbmail2 (2.1.2+20050910-1) experimental; urgency=low + + * snapshot + + -- Paul J Stevens <paul@nfg.nl> Sat, 10 Sep 2005 15:00:09 +0200 + dbmail2 (2.1.2-1) experimental; urgency=low * new upstream release diff --git a/debian/control b/debian/control index e86940ef..a0dfe0d7 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: dbmail2 Section: mail Priority: optional Maintainer: Paul J Stevens <paul@nfg.nl> -Build-Depends: automake, debhelper (>= 4.1.16), dpatch, libglib2.0-dev, libgmime2.1-dev, libldap2-dev, libsqlite0-dev, postgresql-dev, libmysqlclient-dev | libmysqlclient10-dev, pkg-config, libtool +Build-Depends: automake, debhelper (>= 4.1.16), dpatch, libglib2.0-dev, libgmime2.1-dev, libldap2-dev, libsqlite0-dev, postgresql-dev, libmysqlclient-dev | libmysqlclient14-dev, pkg-config, libtool Standards-Version: 3.6.1 Package: dbmail2-pgsql @@ -21,20 +21,12 @@ * * Debugging and memory checking functions */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "debug.h" -#include <stdlib.h> -#include <string.h> -#include <sysexits.h> +#include "dbmail.h" struct debug_mem { long addr; int linenr; char fname[200]; - struct debug_mem *nextaddr; }; @@ -50,7 +42,6 @@ int TRACE_TO_SYSLOG = 1; /* default: yes */ int TRACE_VERBOSE = 0; /* default: no */ int TRACE_LEVEL = 2; /* default: error operations */ - /* * configure the debug settings */ @@ -15,28 +15,24 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + + $Id$ + + headers for debug.c + */ -/* $Id$ - * - * debug.h : headers for debug.c */ +#ifndef _DEBUG_H +#define _DEBUG_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "dbmail.h" -#include <stdio.h> -#include <sys/syslog.h> -#include <stdarg.h> - #ifdef USE_GC #define GC_DEBUG #include <gc/gc.h> #endif -#ifndef _DEBUG_H -#define _DEBUG_H extern int TRACE_TO_SYSLOG; extern int TRACE_VERBOSE; @@ -56,6 +52,19 @@ typedef enum { #define memtst(tstbool) func_memtst (__FILE__,__LINE__,tstbool) +/* Define several macros for GCC specific attributes. + * Although the __attribute__ macro can be easily defined + * to nothing, these macros make them a little prettier. + * */ +#ifdef __GNUC__ +#define UNUSED __attribute__((__unused__)) +#define PRINTF_ARGS(X, Y) __attribute__((format(printf, X, Y))) +#else +#define UNUSED +#define PRINTF_ARGS(X, Y) +#endif + + /* #define dm_malloc(s) __debug_malloc(s, __FILE__, __LINE__) #define dm_free(p) __debug_free(p, __FILE__, __LINE__) @@ -17,16 +17,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "dbmail.h" -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#include "dm_cidr.h" struct cidrfilter * cidr_new(const char *str) { @@ -18,7 +18,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - +#ifndef _DM_CIDR_H +#define _DM_CIDR_H /* * * $Id$ @@ -38,3 +39,4 @@ int cidr_repr(struct cidrfilter *self); int cidr_match(struct cidrfilter *base, struct cidrfilter *test); void cidr_free(struct cidrfilter *self); +#endif diff --git a/dm_getopt.c b/dm_getopt.c index fb3a164a..b7280506 100644 --- a/dm_getopt.c +++ b/dm_getopt.c @@ -25,11 +25,7 @@ * DEALINGS IN THE SOFTWARE. */ -#include <sys/types.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include "dm_getopt.h" +#include "dbmail.h" int dm_optind=1, dm_opterr=1, dm_optopt=0; char *dm_optarg=0; diff --git a/dm_search.c b/dm_search.c index 652dd01f..59b3bb0f 100644 --- a/dm_search.c +++ b/dm_search.c @@ -27,18 +27,7 @@ * by any SQL database. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dm_search.h" -#include "db.h" -#include "dbmailtypes.h" -#include "rfcmsg.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <limits.h> +#include "dbmail.h" /** * abbreviated names of the months @@ -191,7 +180,7 @@ int db_search(unsigned int *rset, unsigned setlen, search_key_t * sk, mailbox_t if (sk->type != IST_SORT) { msn = db_binary_search(mb->seq_list, mb->exists, uid); - if (msn == -1 || msn >= setlen) { + if (msn == -1 || (unsigned)msn >= setlen) { db_free_result(); return 1; } @@ -222,9 +211,9 @@ int db_sort_parsed(unsigned int *rset, unsigned int setlen, unsigned int i; int result, idx = 0; - mime_message_t msg; struct mime_record *mr; sortitems_t *root = NULL; + struct dm_list hdrs; if (!sk->search) return 0; @@ -243,22 +232,17 @@ int db_sort_parsed(unsigned int *rset, unsigned int setlen, if (condition == IST_SUBSEARCH_NOT && rset[i] == 1) continue; - memset(&msg, 0, sizeof(msg)); - - if ((result = db_fetch_headers(mb->seq_list[i], &msg))) + dm_list_init(&hdrs); + + if ((result = db_get_main_header(mb->seq_list[i], &hdrs))) continue; /* ignore parse errors */ - if (dm_list_getstart(&msg.mimeheader)) { - mime_findfield(sk->hdrfld, &msg.mimeheader, &mr); + if (dm_list_getstart(&hdrs)) { + mime_findfield(sk->hdrfld, &hdrs, &mr); if (mr) addto_btree_curr(&root, (char *) mr->value, (i + 1)); } - if (dm_list_getstart(&msg.rfcheader)) { - mime_findfield(sk->hdrfld, &msg.rfcheader, &mr); - if (mr) - addto_btree_curr(&root, (char *) mr->value, (i + 1)); - } - db_free_msg(&msg); + dm_list_free(&hdrs.start); } dm_btree_traverse(root, &idx, rset); /* fill in the rset array with mid's */ @@ -272,6 +256,7 @@ int db_search_parsed(unsigned int *rset, unsigned int setlen, { unsigned i; int result; + u64_t rfcsize; mime_message_t msg; if (mb->exists != setlen) @@ -293,17 +278,16 @@ int db_search_parsed(unsigned int *rset, unsigned int setlen, if (result != 0) continue; /* ignore parse errors */ - if (sk->type == IST_SIZE_LARGER) { - rset[i] = - ((msg.rfcheadersize + msg.bodylines + - msg.bodysize) > sk->size) ? 1 : 0; - } else if (sk->type == IST_SIZE_SMALLER) { - rset[i] = - ((msg.rfcheadersize + msg.bodylines + - msg.bodysize) < sk->size) ? 1 : 0; - } else { + rfcsize = msg.rfcheadersize + msg.bodylines + msg.bodysize; + + if (sk->type == IST_SIZE_LARGER) + rset[i] = (rfcsize > sk->size) ? 1 : 0; + + else if (sk->type == IST_SIZE_SMALLER) + rset[i] = (rfcsize < sk->size) ? 1 : 0; + + else rset[i] = db_exec_search(&msg, sk, mb->seq_list[i]); - } db_free_msg(&msg); } @@ -347,11 +331,10 @@ int db_exec_search(mime_message_t * msg, search_key_t * sk, u64_t msg_idnr) /* do not check children */ if (dm_list_getstart(&msg->rfcheader)) { mime_findfield("date", &msg->rfcheader, &mr); - if (mr - && strlen(mr->value) >= - strlen("Day, d mon yyyy ")) + if (mr && strlen(mr->value) >= strlen("Day, d mon yyyy ")) { + /* 01234567890123456 */ - { + givendate = num_from_imapdate(sk->search); if (mr->value[6] == ' ') @@ -379,13 +362,11 @@ int db_exec_search(mime_message_t * msg, search_key_t * sk, u64_t msg_idnr) mr = (struct mime_record *) el->data; for (i = 0; mr->field[i]; i++) - if (strncasecmp(&mr->field[i], sk->search, - strlen(sk->search)) == 0) + if (strncasecmp(&mr->field[i], sk->search, strlen(sk->search)) == 0) return 1; for (i = 0; mr->value[i]; i++) - if (strncasecmp(&mr->value[i], sk->search, - strlen(sk->search)) == 0) + if (strncasecmp(&mr->value[i], sk->search, strlen(sk->search)) == 0) return 1; el = el->nextnode; @@ -396,13 +377,11 @@ int db_exec_search(mime_message_t * msg, search_key_t * sk, u64_t msg_idnr) mr = (struct mime_record *) el->data; for (i = 0; mr->field[i]; i++) - if (strncasecmp(&mr->field[i], sk->search, - strlen(sk->search)) == 0) + if (strncasecmp(&mr->field[i], sk->search, strlen(sk->search)) == 0) return 1; for (i = 0; mr->value[i]; i++) - if (strncasecmp(&mr->value[i], sk->search, - strlen(sk->search)) == 0) + if (strncasecmp(&mr->value[i], sk->search, strlen(sk->search)) == 0) return 1; el = el->nextnode; @@ -423,14 +402,13 @@ int db_exec_search(mime_message_t * msg, search_key_t * sk, u64_t msg_idnr) if (mr && strncasecmp(mr->value, "text", 4) != 0) break; - return db_search_range(msg->bodystart, msg->bodyend, - sk->search, msg_idnr); + return db_search_range(msg->bodystart, msg->bodyend, sk->search, msg_idnr); } + /* no match found yet, try the children */ el = dm_list_getstart(&msg->children); while (el) { - if (db_exec_search - ((mime_message_t *) el->data, sk, msg_idnr) == 1) + if (db_exec_search((mime_message_t *) el->data, sk, msg_idnr) == 1) return 1; el = el->nextnode; @@ -438,8 +416,7 @@ int db_exec_search(mime_message_t * msg, search_key_t * sk, u64_t msg_idnr) return 0; } -int db_search_range(db_pos_t start, db_pos_t end, - const char *key, u64_t msg_idnr) +int db_search_range(db_pos_t start, db_pos_t end, const char *key, u64_t msg_idnr) { unsigned i, j; unsigned startpos, endpos; @@ -491,8 +468,7 @@ int db_search_range(db_pos_t start, db_pos_t end, /* just one block? */ if (start.block == end.block) { for (i = start.pos; i <= end.pos - strlen(key); i++) { - if (strncasecmp(&query_result[i], key, strlen(key)) - == 0) { + if (strncasecmp(&query_result[i], key, strlen(key)) == 0) { db_free_result(); return 1; } @@ -516,14 +492,12 @@ int db_search_range(db_pos_t start, db_pos_t end, } startpos = (i == start.block) ? start.pos : 0; - endpos = - (i == end.block) ? end.pos + 1 : db_get_length(i, 0); + endpos = (i == end.block) ? end.pos + 1 : db_get_length(i, 0); distance = endpos - startpos; for (j = 0; j < distance - strlen(key); j++) { - if (strncasecmp(&query_result[i], key, strlen(key)) - == 0) { + if (strncasecmp(&query_result[i], key, strlen(key)) == 0) { db_free_result(); return 1; } diff --git a/dm_search.h b/dm_search.h index 29f8e4a2..3de3b472 100644 --- a/dm_search.h +++ b/dm_search.h @@ -27,11 +27,7 @@ #ifndef _DBSEARCH_H #define _DBSEARCH_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmailtypes.h" +#include "dbmail.h" /** @@ -21,13 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <stdlib.h> -#include <string.h> - -#include "dsn.h" -#include "list.h" -#include "auth.h" -#include "debug.h" +#include "dbmail.h" /* Enhanced Status Codes from RFC 1893 * Nota Bene: should be updated to include @@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <dbmailtypes.h> +#include "dbmail.h" typedef enum { DSN_CLASS_NONE = 0, @@ -21,20 +21,7 @@ * * takes care of forwarding mail to an external address */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include "db.h" #include "dbmail.h" -#include "debug.h" -#include "forward.h" -#include "list.h" /* For each of the addresses or programs in targets, * send out a copy of the message pointed to by msgidnr. @@ -23,10 +23,6 @@ #ifndef _FORWARD_H #define _FORWARD_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #define FW_SENDMAIL SENDMAIL int forward(u64_t msgidnr, struct dm_list *targets, const char *from, @@ -23,23 +23,7 @@ * implements an IMAP 4 rev 1 server. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include "imap4.h" -#include "imaputil.h" -#include "imapcommands.h" -#include "dbmail-imapsession.h" -#include "misc.h" -#include "debug.h" -#include "db.h" -#include "auth.h" +#include "dbmail.h" #define MAX_LINESIZE (10*1024) #define COMMAND_SHOW_LEVEL TRACE_INFO @@ -25,11 +25,7 @@ #ifndef _IMAP4_H #define _IMAP4_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmailtypes.h" +#include "dbmail.h" #define IMAP_SERVER_VERSION VERSION //#define IMAP_CAPABILITY_STRING "IMAP4 IMAP4rev1 AUTH=LOGIN ACL NAMESPACE SORT" diff --git a/imapcommands.c b/imapcommands.c index 5533f790..8baad39e 100644 --- a/imapcommands.c +++ b/imapcommands.c @@ -24,38 +24,12 @@ * IMAP server command implementations */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "dbmail.h" #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -/* dbmail.h is included first */ -#include "dbmail.h" -#include "dbmail-imapsession.h" -#include "acl.h" -#include "auth.h" -#include "db.h" - -#include "dbmsgbuf.h" -#include "debug.h" -#include "imapcommands.h" -#include "imaputil.h" -#include "memblock.h" -#include "misc.h" -#include "quota.h" -#include "rfcmsg.h" - -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> - -#include <time.h> -#include <unistd.h> - #ifndef MAX_LINESIZE #define MAX_LINESIZE 1024 #endif @@ -75,8 +49,6 @@ const char *imap_flag_desc_escaped[IMAP_NFLAGS] = { int list_is_lsub = 0; -extern cache_t cached_msg; - extern const char AcceptedMailboxnameChars[]; extern int imap_before_smtp; @@ -1823,7 +1795,6 @@ int _ic_fetch(struct ImapSession *self) } } - mreset(cached_msg.tmpdump); dbmail_imap_session_printf(self, "%s OK %sFETCH completed\r\n", self->tag, self->use_uid ? "UID " : ""); return 0; } diff --git a/imapcommands.h b/imapcommands.h index 0f049e21..c1c8d0d7 100644 --- a/imapcommands.h +++ b/imapcommands.h @@ -27,11 +27,7 @@ #ifndef _IMAP_COMMANDS_H #define _IMAP_COMMANDS_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "imap4.h" +#include "dbmail.h" #include "dbmail-imapsession.h" /* any-state commands */ @@ -24,24 +24,7 @@ * main prg for imap daemon */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <signal.h> -#include <errno.h> -#include "imap4.h" -#include "server.h" -#include "debug.h" -#include "misc.h" -#include "pidfile.h" #include "dbmail.h" -#include <gmime/gmime.h> #define PNAME "dbmail/imap4d" diff --git a/lib/Makefile.am b/lib/Makefile.am index a973cc02..72f18ee3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -16,4 +16,4 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -SUBDIRS = iniparser-2.14
\ No newline at end of file +SUBDIRS = iniparser-2.14 @@ -21,16 +21,7 @@ * * functions to create lists and add/delete items */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "debug.h" -#include "list.h" -#include "misc.h" +#include "dbmail.h" void dm_list_init(struct dm_list *tlist) { @@ -24,10 +24,7 @@ #ifndef _LIST_H #define _LIST_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - +#include <glib.h> #include <sys/types.h> /* @@ -51,7 +48,8 @@ struct element *dm_list_nodeadd(struct dm_list *tlist, const void *data, struct element *dm_list_nodedel(struct dm_list *tlist, void *data); struct element *dm_list_nodepop(struct dm_list *list); -/*@dependent@*/ struct element *dm_list_getstart(struct dm_list *tlist); +struct element *dm_list_getstart(struct dm_list *tlist); + void dm_list_free(struct element **start); long dm_list_length(struct dm_list *tlist); void dm_list_show(struct dm_list *tlist); @@ -21,20 +21,7 @@ * * implementation for lmtp commands according to RFC 1081 */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "dbmail.h" -#include "lmtp.h" -#include "pipe.h" -#include "dbmail-message.h" -#include "db.h" -#include "dsn.h" -#include "debug.h" -#include "dbmailtypes.h" -#include "auth.h" -#include "lmtp.h" #define INCOMING_BUFFER_SIZE 512 @@ -595,7 +582,6 @@ int lmtp(void *stream, void *instream, char *buffer, struct dm_list headerfields; struct element *element; struct DbmailMessage *msg; - char *headers; char *s; dm_list_init(&headerfields); @@ -608,28 +594,27 @@ int lmtp(void *stream, void *instream, char *buffer, return 1; } - s = dbmail_message_to_string(msg, FALSE); + s = dbmail_message_to_string(msg); trace(TRACE_DEBUG, "%s,%s: whole message = %s", __FILE__, __func__, s); g_free(s); if (dbmail_message_get_hdrs_size(msg, FALSE) > READ_BLOCK_SIZE) { - trace(TRACE_ERROR, "main(): header is too big"); + trace(TRACE_ERROR, "%s,%s: header is too big", + __FILE__, __func__); discard_client_input((FILE *) instream); ci_write((FILE *)stream, "500 Error reading header, " "header too big.\r\n"); return 1; } /* Parse the list and scan for field and content */ - headers = dbmail_message_hdrs_to_string(msg, FALSE); - if (mime_fetch_headers(headers, &headerfields) < 0) { - trace(TRACE_ERROR, "main(): fatal error from mime_fetch_headers()"); + if (!(msg = mime_fetch_headers(msg, &headerfields))) { + trace(TRACE_ERROR, "%s,%s: fatal error from mime_fetch_headers()", + __FILE__, __func__); discard_client_input((FILE *) instream); ci_write((FILE *) stream, "500 Error reading header.\r\n"); dbmail_message_free(msg); - g_free(headers); return 1; } - g_free(headers); if (insert_messages(msg, &headerfields, &rcpt, &from) == -1) { ci_write((FILE *) stream, "503 Message not received\r\n"); @@ -25,32 +25,7 @@ #ifndef _LMTP_H #define _LMTP_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <sys/wait.h> -#include <signal.h> -#include <time.h> - -#include "misc.h" -#include "list.h" -#include "debug.h" #include "dbmail.h" -#include "dbmailtypes.h" /* processes */ @@ -24,25 +24,7 @@ * main prg for lmtp daemon */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <signal.h> -#include <errno.h> -#include "imap4.h" -#include "server.h" -#include "debug.h" -#include "misc.h" -#include "pidfile.h" #include "dbmail.h" -#include "lmtp.h" -#include <gmime/gmime.h> #define PNAME "dbmail/lmtpd" @@ -21,22 +21,7 @@ * * main file for dbmail-smtp */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "dbmail.h" -#include "dbmail-message.h" -#include "main.h" -#include "pipe.h" -#include "list.h" -#include "auth.h" -#include "dsn.h" -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sysexits.h> -#include <gmime/gmime.h> #define MESSAGEIDSIZE 100 #define NORMAL_DELIVERY 1 @@ -98,7 +83,6 @@ int main(int argc, char *argv[]) int exitcode = 0; int c, c_prev = 0, usage_error = 0; struct DbmailMessage *msg = NULL; - char *headers = NULL; g_mime_init(0); @@ -302,8 +286,7 @@ int main(int argc, char *argv[]) } /* parse the list and scan for field and content */ - headers = dbmail_message_hdrs_to_string(msg, FALSE); - if (mime_fetch_headers(headers, &mimelist) < 0) { + if (! (msg = mime_fetch_headers(msg, &mimelist))) { trace(TRACE_ERROR, "main(): mime_fetch_headers failed to read a header list"); exitcode = EX_TEMPFAIL; @@ -409,7 +392,6 @@ int main(int argc, char *argv[]) db_disconnect(); auth_disconnect(); config_free(); - g_free(headers); g_mime_shutdown(); @@ -1,34 +0,0 @@ -/* - Copyright (C) 1999-2004 IC & S dbmail@ic-s.nl - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* $Id$ - */ - -#ifndef _MAIN_H -#define _MAIN_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "debug.h" -#include "list.h" -#include "db.h" - -#endif diff --git a/maintenance.c b/maintenance.c index b57d27cf..56a0fa22 100644 --- a/maintenance.c +++ b/maintenance.c @@ -24,24 +24,11 @@ * deleted messages. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "maintenance.h" -#include "db.h" -#include "debug.h" #include "dbmail.h" -#include "list.h" -#include "debug.h" -#include "auth.h" -#include <unistd.h> -#include <time.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <string.h> -#include <gmime/gmime.h> + +#define LEN 30 +#define PNAME "dbmail/maintenance" + /* Loudness and assumptions. */ int yes_to_all = 0; @@ -52,9 +39,6 @@ int quiet = 0; /* Don't print errors. */ int reallyquiet = 0; -#define qprintf(fmt, args...) \ - (quiet ? 0 : printf(fmt, ##args) ) - #define qverbosef(fmt, args...) \ (!verbose ? 0 : printf(fmt, ##args) ) @@ -40,16 +40,7 @@ * */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_ENDIAN_H -#include <endian.h> -#endif - -#include <string.h> /* for memcpy() */ -#include "md5.h" +#include "dbmail.h" /* If endian.h is present, it will tell us, otherwise * autoconf's AC_C_BIGENDIAN will have tested the host. */ @@ -24,10 +24,6 @@ #ifndef GdmMD5_H #define GdmMD5_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - typedef unsigned int uint32; struct GdmMD5Context { @@ -25,16 +25,7 @@ * implementations of functions declared in memblock.h */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "memblock.h" -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include "debug.h" +#include "dbmail.h" #define MAX_ERROR_SIZE 128 @@ -30,10 +30,6 @@ #ifndef _MEMBLOCK_H #define _MEMBLOCK_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #define _MEMBLOCK_SIZE (512ul*1024ul) struct memblock { @@ -22,38 +22,7 @@ * Functions for parsing a mime mailheader (actually just for scanning for email messages and parsing the messageID */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "mime.h" -#include "debug.h" -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "dbmail-message.h" - -/* return 1 if this is the end of a header. That is, it returns 1 if - * the next character is a non-whitespace character, or a newline or - * carriage return + newline. If the next character is a white space - * character, but not a newline, or carriage return + newline, the - * header continues. - */ -static int is_end_of_header(const char *s) -{ - if (!isspace(s[1])) - return 1; - - if (s[1] == '\n') - return 1; - - if (s[1] == '\r' && s[2] == '\n') - return 1; - - return 0; -} +#include "dbmail.h" static void _register_header(const char *field, const char *value, gpointer mimelist) { @@ -72,26 +41,23 @@ static void _register_header(const char *field, const char *value, gpointer mime * copy the header names and values to a dm_list of mime_records. */ -int mime_fetch_headers(const char *datablock, struct dm_list *mimelist) +struct DbmailMessage * mime_fetch_headers(struct DbmailMessage *message, struct dm_list *mimelist) { - GMimeMessage *message; - GString *raw = g_string_new(datablock); - struct DbmailMessage *m = dbmail_message_new(); - if (! m) - trace(TRACE_FATAL,"%s,%s: oom", __FILE__, __func__); + GMimeMessage *m; + GString *s; + + g_return_val_if_fail(message!=NULL,NULL); - m = dbmail_message_init_with_string(m, raw); - g_mime_header_foreach(m->content->headers, _register_header, (gpointer)mimelist); - g_string_free(raw,TRUE); + g_mime_header_foreach(message->content->headers, _register_header, (gpointer)mimelist); /* dbmail expects the mime-headers of the message's mimepart as part of the rfcheaders */ - if (dbmail_message_get_class(m) == DBMAIL_MESSAGE && GMIME_MESSAGE(m->content)->mime_part) { - message = (GMimeMessage *)(m->content); - g_mime_header_foreach(GMIME_OBJECT(message->mime_part)->headers, _register_header, (gpointer)mimelist); + if (dbmail_message_get_class(message) == DBMAIL_MESSAGE && GMIME_MESSAGE(message->content)->mime_part) { + m = (GMimeMessage *)(message->content); + g_mime_header_foreach(GMIME_OBJECT(m->mime_part)->headers, _register_header, (gpointer)mimelist); } + trace(TRACE_DEBUG,"%s,%s: found [%ld] mime headers", __FILE__, __func__, dm_list_length(mimelist)); - dbmail_message_free(m); - return 0; + return message; } @@ -111,33 +77,33 @@ int mime_fetch_headers(const char *datablock, struct dm_list *mimelist) * if blkdata[0] == \n no header is expected and the function will return immediately * (headersize 0) * - * returns -1 on parse failure, -2 on memory error; 0 on succes + * returns -1 on parse failure, -2 on memory error; number of lines on succes */ -int mime_readheader(const char *datablock, u64_t * msgbuf_idx, struct dm_list *mimelist, u64_t * headersize) +int mime_readheader(struct DbmailMessage *message, u64_t * msgbuf_idx, struct dm_list *mimelist, u64_t * headersize) { + int l; char *raw, *crlf; - struct DbmailMessage *message; - GString *mimepart = g_string_new(datablock); - - /* moved header-parsing to separate function */ - mime_fetch_headers(datablock, mimelist); - message = dbmail_message_new(); - message = dbmail_message_init_with_string(message,mimepart); - g_string_free(mimepart,TRUE); + /* moved header-parsing to separate function */ + message = mime_fetch_headers(message, mimelist); + g_return_val_if_fail(message!=NULL,-1); + + raw = dbmail_message_hdrs_to_string(message); + crlf = get_crlf_encoded(raw); - crlf = dbmail_message_hdrs_to_string(message,TRUE); - raw = dbmail_message_hdrs_to_string(message,FALSE); + *headersize = strlen(raw); + *msgbuf_idx += *headersize; - *headersize = strlen(crlf); - *msgbuf_idx = strlen(raw); + l = dm_list_length(mimelist); g_free(crlf); g_free(raw); - return (*headersize - *msgbuf_idx); + trace(TRACE_DEBUG,"%s,%s: return [%d] headerlines", + __FILE__, __func__, l); + return l; } /* @@ -165,7 +131,7 @@ void mime_findfield(const char *fname, struct dm_list *mimelist, } -int mail_address_build_list(char *scan_for_field, struct dm_list *targetlist, +int mail_address_build_list(const char *scan_for_field, struct dm_list *targetlist, struct dm_list *mimelist) { struct mime_record *mr; @@ -23,11 +23,7 @@ #ifndef _MIME_H #define _MIME_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmailtypes.h" +#include "dbmail.h" #define MEM_BLOCK 1024 @@ -43,10 +39,9 @@ struct mime_record { void mime_findfield(const char *fname, struct dm_list *mimelist, struct mime_record **mr); -int mail_address_build_list(char *scan_for_field, struct dm_list *targetlist, +int mail_address_build_list(const char *scan_for_field, struct dm_list *targetlist, struct dm_list *mimelist); -int mime_readheader(const char *datablock, u64_t * blkidx, - struct dm_list *mimelist, u64_t * headersize); -int mime_fetch_headers(const char *datablock, struct dm_list *mimelist); +int mime_readheader(struct DbmailMessage *message, u64_t * blkidx, struct dm_list *mimelist, u64_t * headersize); +struct DbmailMessage * mime_fetch_headers(struct DbmailMessage *message, struct dm_list *mimelist); #endif @@ -21,23 +21,9 @@ * * Miscelaneous functions */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#include <sys/time.h> -#include <time.h> -#include <assert.h> -#include <fnmatch.h> - -#include "auth.h" #include "dbmail.h" -#include "dbmd5.h" -#include "misc.h" -#include "dm_cidr.h" + + #undef max #define max(x,y) ( (x) > (y) ? (x) : (y) ) @@ -548,7 +534,7 @@ GList * g_list_append_printf(GList * list, char * format, ...) char * dm_stresc(const char * from) { char *to; - if (! (to = g_malloc0(sizeof(from) * strlen(from) * 2 + 1))) + if (! (to = g_new0(char,(strlen(from)+1) * 2 + 1))) return NULL; db_escape_string(to, from, strlen(from)); return to; @@ -23,21 +23,7 @@ #ifndef _MISC_H #define _MISC_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <grp.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <arpa/inet.h> -#include <sys/un.h> -#include <netinet/in.h> -#include <unistd.h> -#include <pwd.h> -#include "db.h" -#include "debug.h" -#include "list.h" +#include "dbmail.h" #define BUFLEN 2048 diff --git a/mysql/dbmysql.c b/mysql/dbmysql.c index 479bdd87..e343279f 100644 --- a/mysql/dbmysql.c +++ b/mysql/dbmysql.c @@ -25,16 +25,9 @@ * functions for connecting and talking to the Mysql database */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "db.h" -#include "mysql.h" #include "dbmail.h" -#include "dbmailtypes.h" +#include "mysql.h" -#include <string.h> #define DB_MYSQL_STANDARD_PORT 3306 @@ -26,16 +26,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <sys/types.h> /* for pid_t */ -#include <signal.h> /* for kill() */ -#include <errno.h> /* for ESHRC */ -#include <stdio.h> /* for f...() */ -#include <string.h> /* for memset() */ -#include <stdlib.h> /* for atoi() */ - #include "dbmail.h" -#include "debug.h" -#include "pidfile.h" /* These are used by pidfile_remove. */ static FILE *pidfile_to_close = NULL; @@ -1,2 +0,0 @@ - -void pidfile_create(const char *pidFile, pid_t pid); @@ -21,33 +21,8 @@ * * Functions for reading the pipe from the MTA */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "db.h" -#include "auth.h" -#include "debug.h" -#include "list.h" -#include "forward.h" -#include "sort.h" #include "dbmail.h" -#include "pipe.h" -#include "debug.h" -#include "misc.h" -#include "mime.h" -#include <errno.h> -#include <string.h> -#include <strings.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <unistd.h> -#include "dbmd5.h" -#include "misc.h" -#include "dsn.h" -#include "dbmail-message.h" + #define HEADER_BLOCK_SIZE 1024 #define QUERY_SIZE 255 @@ -466,7 +441,7 @@ int insert_messages(struct DbmailMessage *message, break; } - header = dbmail_message_hdrs_to_string(message, FALSE); + header = dbmail_message_hdrs_to_string(message); headersize = (u64_t)dbmail_message_get_hdrs_size(message, FALSE); bodysize = (u64_t)dbmail_message_get_body_size(message, FALSE); rfcsize = (u64_t)dbmail_message_get_rfcsize(message); @@ -23,12 +23,7 @@ #ifndef _PIPE_H #define _PIPE_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "dbmail-message.h" -#include "list.h" +#include "dbmail.h" /** * \brief inserts a message in the database. The header of the message is @@ -10,24 +10,7 @@ * */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "debug.h" -#include "serverchild.h" -#include "pool.h" -#include <stdio.h> -#include <stdlib.h> -#include <fcntl.h> -#include <unistd.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/shm.h> -#include <time.h> -#include <errno.h> -#include <string.h> +#include "dbmail.h" #define P_SIZE 100000 @@ -7,16 +7,7 @@ #ifndef POOL_H #define POOL_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> #include "dbmail.h" -#include <sys/mman.h> -#include <sys/types.h> -#include "server.h" -#include "serverchild.h" #define HARD_MAX_CHILDREN 50 @@ -21,18 +21,8 @@ * * implementation for pop3 commands according to RFC 1081 */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "dbmail.h" -#include "pop3.h" -#include "db.h" -#include "debug.h" -#include "dbmailtypes.h" -#include "auth.h" -#include "pop3.h" -#include "misc.h" #define INCOMING_BUFFER_SIZE 512 #define APOP_STAMP_SIZE 255 @@ -24,31 +24,7 @@ #ifndef _POP3_H #define _POP3_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <sys/wait.h> -#include <signal.h> - -#include "misc.h" -#include "list.h" -#include "debug.h" #include "dbmail.h" -#include "dbmailtypes.h" /* processes */ #define MAXCHILDREN 5 @@ -24,27 +24,7 @@ * main prg for pop3 daemon */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <signal.h> -#include <unistd.h> -#include <errno.h> -#include <unistd.h> /* for getopt() */ -#include "server.h" -#include "debug.h" -#include "misc.h" -#include "pidfile.h" #include "dbmail.h" -#include "dbmailtypes.h" -#include "pop3.h" -#include <gmime/gmime.h> #define PNAME "dbmail/pop3d" diff --git a/python/lib/dbmail.py b/python/lib/dbmail.py index 0ffb6352..7eeaf98d 100644 --- a/python/lib/dbmail.py +++ b/python/lib/dbmail.py @@ -113,7 +113,7 @@ class Dbmail(DbmailConfig): self._cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) else: - raise novalidDriver, "no postgres driver available" + raise novalidDriver, "no postgres driver available (PgSQL or psycopg2)" assert(self._cursor) @@ -131,24 +131,26 @@ class DbmailAlias(Dbmail): def get(self,alias,deliver_to=None): c=self.getCursor() filter='' - if deliver_to: filter="AND deliver_to='%s'" % deliver_to - c.execute("select * from %saliases where alias='%s' %s" % (self._prefix, alias,filter)) + q="select * from %saliases where alias=%%s" % self._prefix + if deliver_to: + q="%s AND deliver_to=%%s" % q + c.execute(q,(alias, deliver_to,)) + else: + c.execute(q,(alias,)) return c.fetchall() def set(self,alias,deliver_to): c=self.getCursor() - q="""INSERT INTO %saliases (alias,deliver_to) VALUES - ('%s','%s')""" %(self._prefix,alias,deliver_to) + q="""INSERT INTO %saliases (alias,deliver_to) VALUES (%%s,%%s)""" % self._prefix if not self.get(alias,deliver_to): assert(alias and deliver_to) - c.execute(q) + c.execute(q, (alias,deliver_to,)) def delete(self,alias,deliver_to): c=self.getCursor() - q="""DELETE FROM %saliases WHERE alias='%s' AND - deliver_to='%s'""" %(self._prefix,alias,deliver_to) + q="""DELETE FROM %saliases WHERE alias=%%s AND deliver_to=%%s""" % self._prefix if self.get(alias,deliver_to): - c.execute(q) + c.execute(q, (alias,deliver_to,)) class DbmailUser(Dbmail): _dirty=1 @@ -157,6 +159,10 @@ class DbmailUser(Dbmail): Dbmail.__init__(self) self.setUserid(userid) self._userdict={} + + def create(self): pass + def update(self): pass + def delete(self): pass def setDirty(self,dirty=1): self._dirty=dirty def getDirty(self): return self._dirty @@ -168,8 +174,9 @@ class DbmailUser(Dbmail): if not self.getDirty() and self._userdict: return self._userdict + q="select * from %susers where userid=%%s" % self._prefix c=self.getCursor() - c.execute("select * from %susers where userid='%s'" % (self._prefix,self.getUserid())) + c.execute(q,(self.getUserid(),)) dict = c.fetchone() assert(dict) self._userdict = dict @@ -185,15 +192,18 @@ class DbmailAutoreply(Dbmail): def __init__(self,userid,file=None): Dbmail.__init__(self,file) + self._table="%sauto_replies" % self._prefix self.setUser(DbmailUser(userid)) + assert(self.getUser() != None) def setUser(self,user): self._user=user def getUser(self): return self._user def get(self): c=self.getCursor() + q="""select reply_body from %s where user_idnr=%%s""" % self._table try: - c.execute("select reply_body from %sauto_replies where user_idnr='%s'" %(self._prefix,self.getUser().getUidNumber())) + c.execute(q, (self.getUser().getUidNumber())) dict = c.fetchone() assert(dict) except AssertionError: @@ -201,18 +211,16 @@ class DbmailAutoreply(Dbmail): if dict: return dict['reply_body'] - getReply = get - def set(self,message): - c=self.getCursor() - c.execute("insert into %sauto_replies (user_idnr,reply_body) values ('%s','%s')" %(self._prefix,self.getUser().getUidNumber(),message)) + q="""insert into %s (user_idnr,reply_body) values (%%s,%%s)""" % self._table + self.getCursor().execute(q, (self.getUser().getUidNumber(),message,)) - setReply = set - def delete(self): - c=self.getCursor() - c.execute("delete from %sauto_replies where user_idnr='%s'" % (self._prefix,self.getUser().getUidNumber())) + q="""delete from %s where user_idnr=%%s""" % self._table + self.getCursor().execute(q, (self.getUser().getUidNumber())) + getReply = get + setReply = set delReply = delete if __name__=='__main__': @@ -275,7 +283,8 @@ if __name__=='__main__': self.o = DbmailAutoreply('testuser1') def testSet(self): - self.o.set("test reply message") + self.failUnlessRaises(TypeError, self.o.set, """test '' \0 reply message""") + self.o.set("""test '' reply message""") self.failUnless(self.o.get()) self.o.delete() @@ -18,15 +18,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <string.h> -#include "db.h" -#include "auth.h" -#include "quota.h" +#include "dbmail.h" + /* Allocate a quota structure for `n_resources' resources. * Returns NULL on failure. @@ -21,13 +21,8 @@ #ifndef _DBMAIL_QUOTA_H #define _DBMAIL_QUOTA_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "dbmailtypes.h" - /* A resource type. * RT_STORAGE: "STORAGE" */ @@ -23,22 +23,25 @@ * compliant mail message */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "rfcmsg.h" -#include "list.h" -#include "debug.h" -#include "mime.h" -#include "dbmsgbuf.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> - -static int db_parse_as_text(mime_message_t * msg); -static int db_start_msg(mime_message_t * msg, char *stopbound, int *level, int maxlevel); + +#include "dbmail.h" + +static int db_start_msg(struct DbmailMessage *message, mime_message_t * msg, char *stopbound, int *level, int maxlevel); + +/* + * frees all the memory associated with a msg + */ +mime_message_t * db_new_msg(void) +{ + mime_message_t *m = g_new0(mime_message_t,1); + + dm_list_init(&m->children); + dm_list_init(&m->rfcheader); + dm_list_init(&m->mimeheader); + + return m; + +} /* * frees all the memory associated with a msg @@ -119,83 +122,15 @@ static void db_reverse_msg(mime_message_t * msg) int db_fetch_headers(u64_t msguid, mime_message_t * msg) { int result, level = 0, maxlevel = -1; + struct DbmailMessage *message; - if (db_init_fetch_message(msguid) != 1) { + if (!(message = db_init_fetch_message(msguid, DBMAIL_MESSAGE_FILTER_FULL))) { trace(TRACE_ERROR, "%s,%s: could not init msgfetch\n", __FILE__, __func__); return -2; } - result = db_start_msg(msg, NULL, &level, maxlevel); /* fetch message */ - if (result < 0) { - trace(TRACE_INFO, "%s,%s: error fetching message ID [%llu] at level [%d]\n", - __FILE__, __func__, msguid, level); - db_close_msgfetch(); - db_free_msg(msg); - - if (result < -1) - return result; /* memory/dbase error */ - - /* - * so an error occurred parsing the message. - * try to lower the maxlevel of recursion - */ - - for (maxlevel = level - 1; maxlevel >= 0; maxlevel--) { - trace(TRACE_DEBUG, "%s,%s: trying to fetch at maxlevel [%d]...", - __FILE__, __func__, maxlevel); - - if (db_init_fetch_message(msguid) != 1) { - trace(TRACE_ERROR, "%s,%s: could not init msgfetch", - __FILE__, __func__); - return -2; - } - - level = 0; - result = db_start_msg(msg, NULL, &level, maxlevel); - - db_close_msgfetch(); - - if (result != -1) - break; - - db_free_msg(msg); - } - - if (result < -1) { - db_free_msg(msg); - return result; - } - - if (result >= 0) { - trace(TRACE_WARNING, "%s,%s: succesfully recovered erroneous message [%llu]", - __FILE__, __func__, msguid); - db_reverse_msg(msg); - return 0; - } - - - /* ok still problems... try to make a message */ - if (db_init_fetch_message(msguid) != 1) { - trace(TRACE_ERROR, "%s,%s: could not init msgfetch", - __FILE__, __func__); - return -2; - } - - result = db_parse_as_text(msg); - if (result < 0) { - /* probably some serious dbase error */ - trace(TRACE_ERROR, "%s,%s: could not recover message as plain text", - __FILE__, __func__); - db_free_msg(msg); - return result; - } - - trace(TRACE_WARNING, "%s,%s: message recovered as plain text", - __FILE__, __func__); - db_close_msgfetch(); - return -1; - } + result = db_start_msg(message, msg, NULL, &level, maxlevel); /* fetch message */ db_reverse_msg(msg); @@ -216,628 +151,27 @@ int db_fetch_headers(u64_t msguid, mime_message_t * msg) * * returns the number of lines parsed or -1 on parse error, -2 on dbase error, -3 on memory error */ -int db_start_msg(mime_message_t * msg, char *stopbound, int *level, int maxlevel) +int db_start_msg(struct DbmailMessage *message, mime_message_t * msg, char *stopbound, int *level, int maxlevel) { - int len, sblen, result, totallines = 0, nlines, hdrlines; + int totallines = 0, hdrlines; struct mime_record *mr; - char *newbound, *bptr; int continue_recursion = (maxlevel == 0 && *level == 0) ? 0 : 1; trace(TRACE_DEBUG, "%s,%s: starting, stopbound: '%s'\n", __FILE__, __func__, stopbound ? stopbound : "<null>"); - dm_list_init(&msg->children); - msg->message_has_errors = (!continue_recursion); - - /* read header */ if (db_update_msgbuf(MSGBUF_FORCE_UPDATE) == -1) return -2; - if ((hdrlines = mime_readheader(&msgbuf_buf[msgbuf_idx], &msgbuf_idx, &msg->rfcheader, &msg->rfcheadersize)) < 0) + if ((hdrlines = mime_readheader(message, &msgbuf_idx, &msg->rfcheader, &msg->rfcheadersize)) < 0) return hdrlines; /* error reading header */ db_give_msgpos(&msg->bodystart); msg->rfcheaderlines = hdrlines; - mime_findfield("content-type", &msg->rfcheader, &mr); - if (continue_recursion && mr && strncasecmp(mr->value, "multipart", strlen("multipart")) == 0) { - trace(TRACE_DEBUG, "%s,%s: found multipart msg\n", __FILE__, __func__); - - /* multipart msg, find new boundary */ - for (bptr = mr->value; *bptr; bptr++) - if (strncasecmp (bptr, "boundary=", sizeof("boundary=") - 1) == 0) - break; - - if (!bptr) { - trace(TRACE_WARNING, "%s,%s: could not find a new msg-boundary\n", - __FILE__, __func__); - return -1; /* no new boundary ??? */ - } - - bptr += sizeof("boundary=") - 1; - if (*bptr == '\"') { - bptr++; - newbound = bptr; - while (*newbound && *newbound != '\"') - newbound++; - } else { - newbound = bptr; - while (*newbound && !isspace(*newbound) && *newbound != ';') - newbound++; - } - - len = newbound - bptr; - if (!(newbound = (char *) dm_malloc(len + 1))) { - trace(TRACE_ERROR, "%s,%s: out of memory\n", __FILE__, __func__); - return -3; - } - - strncpy(newbound, bptr, len); - newbound[len] = '\0'; - - trace(TRACE_DEBUG, "%s,%s: found new boundary: [%s], msgbuf_idx %llu\n", - __FILE__, __func__, newbound, msgbuf_idx); - - /* advance to first boundary */ - if (db_update_msgbuf(MSGBUF_FORCE_UPDATE) == -1) { - trace(TRACE_ERROR, "%s,%s: error updating msgbuf\n", - __FILE__, __func__); - dm_free(newbound); - return -2; - } - - while (msgbuf_buf[msgbuf_idx]) { - if (strncmp(&msgbuf_buf[msgbuf_idx], newbound, strlen(newbound)) == 0) - break; - - if (msgbuf_buf[msgbuf_idx] == '\n') - totallines++; - - msgbuf_idx++; - } - - if (!msgbuf_buf[msgbuf_idx]) { - trace(TRACE_WARNING, "%s,%s: unexpected end-of-data\n", - __FILE__, __func__); - dm_free(newbound); - return -1; - } - - msgbuf_idx += strlen(newbound); /* skip the boundary */ - msgbuf_idx++; /* skip \n */ - totallines++; /* and count it */ - - /* find MIME-parts */ - (*level)++; - if ((nlines = db_add_mime_children(&msg->children, newbound, level, maxlevel)) < 0) { - trace(TRACE_WARNING, "%s,%s: error adding MIME-children\n", __FILE__, __func__); - dm_free(newbound); - return nlines; - } - (*level)--; - totallines += nlines; - - /* skip stopbound if present */ - if (stopbound) { - sblen = strlen(stopbound); - msgbuf_idx += (2 + sblen); /* double hyphen preceeds */ - } - - dm_free(newbound); - newbound = NULL; - - if (msgbuf_idx > 0) { - /* walk back because bodyend is inclusive */ - msgbuf_idx--; - db_give_msgpos(&msg->bodyend); - msgbuf_idx++; - } else - db_give_msgpos(&msg->bodyend); /* this case should never happen... */ - - - msg->bodysize = db_give_range_size(&msg->bodystart, &msg->bodyend); - msg->bodylines = totallines; - - return totallines + hdrlines; /* done */ - } else { - /* single part msg, read untill stopbound OR end of buffer */ - trace(TRACE_DEBUG, "%s,%s: found singlepart msg\n", __FILE__, __func__); - - if (stopbound) { - sblen = strlen(stopbound); - - while (msgbuf_buf[msgbuf_idx]) { - if (db_update_msgbuf(sblen + 3) == -1) - return -2; - - if (msgbuf_buf[msgbuf_idx] == '\n') - msg->bodylines++; - - if (msgbuf_buf[msgbuf_idx + 1] == '-' - && msgbuf_buf[msgbuf_idx + 2] == '-' - && strncmp(&msgbuf_buf[msgbuf_idx + 3], stopbound, sblen) == 0) { - db_give_msgpos(&msg->bodyend); - msg->bodysize = db_give_range_size(&msg->bodystart, &msg->bodyend); - - msgbuf_idx++; /* msgbuf_buf[msgbuf_idx] == '-' now */ - - /* advance to after stopbound */ - msgbuf_idx += sblen + 2; /* (add 2 cause double hyphen preceeds) */ - while (isspace(msgbuf_buf[msgbuf_idx])) { - if (msgbuf_buf[msgbuf_idx] == '\n') - totallines++; - msgbuf_idx++; - } - - trace(TRACE_DEBUG, "%s,%s: stopbound reached\n", - __FILE__, __func__); - return (totallines + msg->bodylines + hdrlines); - } - - msgbuf_idx++; - } - - /* end of buffer reached, invalid message encountered: there should be a stopbound! */ - /* but lets pretend there's nothing wrong... */ - db_give_msgpos(&msg->bodyend); - msg->bodysize = db_give_range_size(&msg->bodystart, &msg->bodyend); - totallines += msg->bodylines; - - trace(TRACE_WARNING, "%s,%s: no stopbound where expected...\n", - __FILE__, __func__); - -/* return -1; -*/ - } else { - /* walk on till end of buffer */ - result = 1; - while (1) { - for (; msgbuf_idx < msgbuf_buflen - 1 && msgbuf_buf[msgbuf_idx]; msgbuf_idx++) - if (msgbuf_buf[msgbuf_idx] == '\n') - msg->bodylines++; - - if (result == 0) { - /* end of msg reached, one char left in msgbuf */ - if (msgbuf_buf[msgbuf_idx] == '\n') - msg->bodylines++; - - break; - } - - result = db_update_msgbuf(MSGBUF_FORCE_UPDATE); - if (result == -1) - return -2; - } - - db_give_msgpos(&msg->bodyend); - msg->bodysize = db_give_range_size(&msg->bodystart, &msg->bodyend); - totallines += msg->bodylines; - } - } - trace(TRACE_DEBUG, "%s,%s: exit\n", __FILE__, __func__); return totallines; } - - -/* - * assume to enter just after a splitbound - * returns -1 on parse error, -2 on dbase error, -3 on memory error - */ -int db_add_mime_children(struct dm_list *brothers, char *splitbound, - int *level, int maxlevel) -{ - mime_message_t part; - struct mime_record *mr; - int sblen, nlines, totallines = 0, len; - u64_t dummy; - char *bptr, *newbound; - int continue_recursion = (maxlevel < 0 - || *level < maxlevel) ? 1 : 0; - - trace(TRACE_DEBUG, - "db_add_mime_children(): starting, splitbound: '%s'\n", - splitbound); - sblen = strlen(splitbound); - - do { - db_update_msgbuf(MSGBUF_FORCE_UPDATE); - memset(&part, 0, sizeof(part)); - part.message_has_errors = (!continue_recursion); - - /* should have a MIME header right here */ - if ((nlines = - mime_readheader(&msgbuf_buf[msgbuf_idx], &msgbuf_idx, - &part.mimeheader, &dummy)) < 0) { - trace(TRACE_WARNING, - "db_add_mime_children(): error reading MIME-header\n"); - db_free_msg(&part); - return nlines; /* error reading header */ - } - totallines += nlines; - - mime_findfield("content-type", &part.mimeheader, &mr); - - if (continue_recursion && - mr - && strncasecmp(mr->value, "message/rfc822", - strlen("message/rfc822")) == 0) { - trace(TRACE_DEBUG, - "db_add_mime_children(): found an RFC822 message\n"); - - /* a message will follow */ - if ((nlines = - db_start_msg(&part, splitbound, level, - maxlevel)) < 0) { - trace(TRACE_WARNING, - "db_add_mime_children(): error retrieving message\n"); - db_free_msg(&part); - return nlines; - } - trace(TRACE_DEBUG, - "db_add_mime_children(): got %d newlines from start_msg()\n", - nlines); - totallines += nlines; - part.mimerfclines = nlines; - } else if (continue_recursion && - mr - && strncasecmp(mr->value, "multipart", - strlen("multipart")) == 0) { - trace(TRACE_DEBUG, - "db_add_mime_children(): found a MIME multipart sub message\n"); - - /* multipart msg, find new boundary */ - for (bptr = mr->value; *bptr; bptr++) - if (strncasecmp - (bptr, "boundary=", - sizeof("boundary=") - 1) == 0) - break; - - if (!bptr) { - trace(TRACE_WARNING, - "db_add_mime_children(): could not find a new msg-boundary\n"); - db_free_msg(&part); - return -1; /* no new boundary ??? */ - } - - bptr += sizeof("boundary=") - 1; - if (*bptr == '\"') { - bptr++; - newbound = bptr; - while (*newbound && *newbound != '\"') - newbound++; - } else { - newbound = bptr; - while (*newbound && !isspace(*newbound) - && *newbound != ';') - newbound++; - } - - len = newbound - bptr; - if (!(newbound = (char *) dm_malloc(len + 1))) { - trace(TRACE_ERROR, - "db_add_mime_children(): out of memory\n"); - db_free_msg(&part); - return -3; - } - - strncpy(newbound, bptr, len); - newbound[len] = '\0'; - - trace(TRACE_DEBUG, - "db_add_mime_children(): found new boundary: [%s], msgbuf_idx %llu\n", - newbound, msgbuf_idx); - - - /* advance to first boundary */ - if (db_update_msgbuf(MSGBUF_FORCE_UPDATE) == -1) { - trace(TRACE_ERROR, - "db_add_mime_children(): error updating msgbuf\n"); - db_free_msg(&part); - dm_free(newbound); - return -2; - } - - while (msgbuf_buf[msgbuf_idx]) { - if (strncmp - (&msgbuf_buf[msgbuf_idx], newbound, - strlen(newbound)) == 0) - break; - - if (msgbuf_buf[msgbuf_idx] == '\n') { - totallines++; - part.bodylines++; - } - - msgbuf_idx++; - } - - if (!msgbuf_buf[msgbuf_idx]) { - trace(TRACE_WARNING, - "db_add_mime_children(): unexpected end-of-data\n"); - dm_free(newbound); - db_free_msg(&part); - return -1; - } - - msgbuf_idx += strlen(newbound); /* skip the boundary */ - msgbuf_idx++; /* skip \n */ - totallines++; /* and count it */ - part.bodylines++; - db_give_msgpos(&part.bodystart); /* remember position */ - - (*level)++; - if ((nlines = - db_add_mime_children(&part.children, newbound, - level, maxlevel)) < 0) { - trace(TRACE_WARNING, - "db_add_mime_children(): error adding mime children\n"); - dm_free(newbound); - db_free_msg(&part); - return nlines; - } - (*level)--; - - dm_free(newbound); - newbound = NULL; - msgbuf_idx += sblen + 2; /* skip splitbound */ - - if (msgbuf_idx > 0) { - /* walk back because bodyend is inclusive */ - msgbuf_idx--; - db_give_msgpos(&part.bodyend); - msgbuf_idx++; - } else - db_give_msgpos(&part.bodyend); /* this case should never happen... */ - - - part.bodysize = - db_give_range_size(&part.bodystart, - &part.bodyend); - part.bodylines += nlines; - totallines += nlines; - } else { - trace(TRACE_DEBUG, - "db_add_mime_children(): expecting body data...\n"); - - /* just body data follows, advance to splitbound */ - db_give_msgpos(&part.bodystart); - - while (msgbuf_buf[msgbuf_idx]) { - if (db_update_msgbuf(sblen + 3) == -1) { - db_free_msg(&part); - return -2; - } - - if (msgbuf_buf[msgbuf_idx] == '\n') - part.bodylines++; - - if (msgbuf_buf[msgbuf_idx + 1] == '-' - && msgbuf_buf[msgbuf_idx + 2] == '-' - && strncmp(&msgbuf_buf[msgbuf_idx + 3], - splitbound, sblen) == 0) - break; - - msgbuf_idx++; - } - - /* at this point msgbuf_buf[msgbuf_idx] is either - * 0 (end of data) -- invalid message! - * or the character right before '--<splitbound>' - */ - - totallines += part.bodylines; - - if (!msgbuf_buf[msgbuf_idx]) { - trace(TRACE_WARNING, - "db_add_mime_children(): unexpected end of data\n"); - db_free_msg(&part); - return -1; /* ?? splitbound should follow */ - } - - db_give_msgpos(&part.bodyend); - part.bodysize = - db_give_range_size(&part.bodystart, - &part.bodyend); - - msgbuf_idx++; /* msgbuf_buf[msgbuf_idx] == '-' after this statement */ - - msgbuf_idx += sblen + 2; /* skip the boundary & double hypen */ - } - - /* add this part to brother list */ - if (dm_list_nodeadd(brothers, &part, sizeof(part)) == NULL) { - trace(TRACE_WARNING, - "db_add_mime_children(): could not add node\n"); - db_free_msg(&part); - return -3; - } - - /* if double hyphen ('--') follows we're done */ - if (msgbuf_buf[msgbuf_idx] == '-' - && msgbuf_buf[msgbuf_idx + 1] == '-') { - trace(TRACE_DEBUG, - "db_add_mime_children(): found end after boundary [%s],\n", - splitbound); - trace(TRACE_DEBUG, - " followed by [%.*s],\n", - 48, &msgbuf_buf[msgbuf_idx]); - - msgbuf_idx += 2; /* skip hyphens */ - - /* probably some newlines will follow (not specified but often there) */ - while (msgbuf_buf[msgbuf_idx] == '\n') { - totallines++; - msgbuf_idx++; - } - - return totallines; - } - - if (msgbuf_buf[msgbuf_idx] == '\n') { - totallines++; - msgbuf_idx++; /* skip the newline itself */ - } - } - while (msgbuf_buf[msgbuf_idx]); - - trace(TRACE_WARNING, - "db_add_mime_children(): sudden end of message\n"); - return totallines; - -/* trace(TRACE_ERROR,"db_add_mime_children(): invalid message (no ending boundary found)\n"); - return -1; -*/ -} - - -/* - * db_parse_as_text() - * - * parses a message as a block of plain text; an explaining header is created - * note that this will disturb the length calculations... - * this function is called when normal parsing fails. - * - * returns -1 on dbase failure, -2 on memory error - */ -int db_parse_as_text(mime_message_t * msg) -{ - int result; - struct mime_record mr; - struct element *el = NULL; - field_t postmaster; - - memset(msg, 0, sizeof(*msg)); - - strcpy(mr.field, "subject"); - strcpy(mr.value, - "dbmail IMAP server info: this message could not be parsed"); - el = dm_list_nodeadd(&msg->rfcheader, &mr, sizeof(mr)); - if (!el) - return -3; - - strcpy(mr.field, "from"); - config_get_value("POSTMASTER", "DBMAIL", postmaster); - strncpy(mr.value, postmaster, MIME_VALUE_MAX - 1); - el = dm_list_nodeadd(&msg->rfcheader, &mr, sizeof(mr)); - if (!el) - return -3; - - msg->rfcheadersize = - strlen - ("subject: dbmail IMAP server info: this message could not be parsed\r\n") - + strlen("from: imapserver@dbmail.org\r\n"); - msg->rfcheaderlines = 4; - - db_give_msgpos(&msg->bodystart); - - /* walk on till end of buffer */ - result = 1; - while (1) { - for (; msgbuf_idx < msgbuf_buflen - 1; msgbuf_idx++) - if (msgbuf_buf[msgbuf_idx] == '\n') - msg->bodylines++; - - if (result == 0) { - /* end of msg reached, one char left in msgbuf_buf */ - if (msgbuf_buf[msgbuf_idx] == '\n') - msg->bodylines++; - - break; - } - - result = db_update_msgbuf(MSGBUF_FORCE_UPDATE); - if (result == -1) - return -2; - } - - db_give_msgpos(&msg->bodyend); - msg->bodysize = db_give_range_size(&msg->bodystart, &msg->bodyend); - - return 0; -} - - -/* - * db_msgdump() - * - * dumps a message to stderr - * returns the size (in bytes) that the message occupies in memory - */ -int db_msgdump(mime_message_t * msg, u64_t msguid, int level) -{ - struct element *curr; - struct mime_record *mr; - char *spaces; - int size = sizeof(mime_message_t); - - if (level < 0) - return 0; - - if (!msg) { - trace(TRACE_DEBUG, "db_msgdump: got null\n"); - return 0; - } - - spaces = (char *) dm_malloc(3 * level + 1); - if (!spaces) - return 0; - - memset(spaces, ' ', 3 * level); - spaces[3 * level] = 0; - - - trace(TRACE_DEBUG, "%sMIME-header: \n", spaces); - curr = dm_list_getstart(&msg->mimeheader); - if (!curr) - trace(TRACE_DEBUG, "%s%snull\n", spaces, spaces); - else { - while (curr) { - mr = (struct mime_record *) curr->data; - trace(TRACE_DEBUG, "%s%s[%s] : [%s]\n", spaces, - spaces, mr->field, mr->value); - curr = curr->nextnode; - size += sizeof(struct mime_record); - } - } - trace(TRACE_DEBUG, "%s*** MIME-header end\n", spaces); - - trace(TRACE_DEBUG, "%sRFC822-header: \n", spaces); - curr = dm_list_getstart(&msg->rfcheader); - if (!curr) - trace(TRACE_DEBUG, "%s%snull\n", spaces, spaces); - else { - while (curr) { - mr = (struct mime_record *) curr->data; - trace(TRACE_DEBUG, "%s%s[%s] : [%s]\n", spaces, - spaces, mr->field, mr->value); - curr = curr->nextnode; - size += sizeof(struct mime_record); - } - } - trace(TRACE_DEBUG, "%s*** RFC822-header end\n", spaces); - - trace(TRACE_DEBUG, "%s*** Body range:\n", spaces); - trace(TRACE_DEBUG, - "%s%s(%llu, %llu) - (%llu, %llu), size: %llu, newlines: %llu\n", - spaces, spaces, msg->bodystart.block, msg->bodystart.pos, - msg->bodyend.block, msg->bodyend.pos, msg->bodysize, - msg->bodylines); - - trace(TRACE_DEBUG, "%sChildren of this msg:\n", spaces); - - curr = dm_list_getstart(&msg->children); - while (curr) { - size += - db_msgdump((mime_message_t *) curr->data, msguid, - level + 1); - curr = curr->nextnode; - } - trace(TRACE_DEBUG, "%s*** child list end\n", spaces); - - dm_free(spaces); - return size; -} @@ -28,17 +28,13 @@ #ifndef _RFCMSG_H #define _RFCMSG_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "dbmailtypes.h" +mime_message_t * db_new_msg(void); void db_free_msg(mime_message_t * msg); int db_fetch_headers(u64_t msguid, mime_message_t * msg); int db_add_mime_children(struct dm_list *brothers, char *splitbound, int *level, int maxlevel); -int db_msgdump(mime_message_t * msg, u64_t msguid, int level); #endif @@ -24,33 +24,7 @@ * code to implement a network server */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "db.h" -#include "debug.h" -#include "server.h" -#include "pool.h" -#include "serverchild.h" -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <sys/time.h> -#include <sys/wait.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <signal.h> +#include "dbmail.h" int GeneralStopRequested = 0; @@ -27,34 +27,8 @@ #ifndef _SERVER_H #define _SERVER_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#define IPLEN 32 -#define BACKLOG 16 - -#include <signal.h> #include "dbmail.h" -#include "dbmailtypes.h" -#include "serverchild.h" -typedef struct { - int listenSocket; - int startChildren; - int minSpareChildren; - int maxSpareChildren; - int maxChildren; - int childMaxConnect; - int timeout; - char ip[IPLEN]; - int port; - int resolveIP; - char *timeoutMsg; - field_t serverUser, serverGroup; - field_t socket; - int (*ClientHandler) (clientinfo_t *); -} serverConfig_t; int CreateSocket(serverConfig_t * conf); int StartServer(serverConfig_t * conf); diff --git a/serverchild.c b/serverchild.c index 560de8e6..ac82cf9f 100644 --- a/serverchild.c +++ b/serverchild.c @@ -24,31 +24,7 @@ * function implementations of server children code (connection handling) */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "debug.h" -#include "serverchild.h" -#include "db.h" -#include "auth.h" -#include "pool.h" -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <sys/wait.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <signal.h> +#include "dbmail.h" int ChildStopRequested = 0; int connected = 0; diff --git a/serverchild.h b/serverchild.h index 87166016..f4847616 100644 --- a/serverchild.h +++ b/serverchild.h @@ -28,13 +28,7 @@ #ifndef SERVERCHILD_H #define SERVERCHILD_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <sys/types.h> -#include <signal.h> -#include "dbmailtypes.h" +#include "dbmail.h" void active_child_sig_handler(int sig, siginfo_t *info, void *data); void noop_child_sig_handler(int sig, siginfo_t *info, void *data); @@ -21,31 +21,7 @@ * This is dbmail-sievecmd, which provides * a command line interface to the sievescripts */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "sort.h" -#include "sort/sortsieve.h" -#include "sievecmd.h" - -#include "auth.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include "dbmail.h" -#include "list.h" -#include "server.h" -#include "debug.h" -#include "db.h" -#include <time.h> -#include <stdarg.h> -#include <sys/types.h> -#include <unistd.h> -#ifdef HAVE_CRYPT_H -#include <crypt.h> -#endif -#include "dbmd5.h" char *configFile = DEFAULT_CONFIG_FILE; @@ -19,13 +19,10 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#ifndef _SIEVECMD_H +#define _SIEVECMD_H -#include <stdio.h> -#include "dbmailtypes.h" -#include "sort/sortsieve.h" +#include "dbmail.h" #define PNAME "dbmail/sievecmd" @@ -37,3 +34,5 @@ int do_remove(u64_t user_idnr, char *name); int do_insert(u64_t user_idnr, char *name, FILE * source); int read_script_file(FILE * f, char **m_buf); + +#endif @@ -24,27 +24,5 @@ #ifndef _SORTING_H #define _SORTING_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include "dsn.h" -#include "debug.h" -#include "dbmailtypes.h" - -#define SA_KEEP 1 -#define SA_DISCARD 2 -#define SA_REDIRECT 3 -#define SA_REJECT 4 -#define SA_FILEINTO 5 - -typedef struct sort_action { - int method; - char *destination; - char *message; -} sort_action_t; - #endif /* #ifndef _SORTING_H */ diff --git a/sort/sortsieve.c b/sort/sortsieve.c index d0e8c145..2302c92b 100644 --- a/sort/sortsieve.c +++ b/sort/sortsieve.c @@ -25,29 +25,8 @@ * */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <time.h> -#include <ctype.h> -#include "db.h" -#include "auth.h" -#include "debug.h" -#include "list.h" #include "dbmail.h" -#include "debug.h" -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <unistd.h> -#include "dbmd5.h" -#include "misc.h" - -#include "sortsieve.h" -#include "sort.h" + #include <sieve2_interface.h> extern struct dm_list smtpItems, sysItems; diff --git a/sort/sortsieve.h b/sort/sortsieve.h index 6abd7bb9..30b4612f 100644 --- a/sort/sortsieve.h +++ b/sort/sortsieve.h @@ -21,12 +21,8 @@ #ifndef _SIEVE_H #define _SIEVE_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "dbmail.h" -#include "sort.h" -#include "dbmailtypes.h" #include <sieve2_interface.h> #define MAX_SIEVE_SCRIPTNAME 100 diff --git a/sql/mysql/create_tables.mysql b/sql/mysql/create_tables.mysql index 8cb0a2ed..e14c76da 100644 --- a/sql/mysql/create_tables.mysql +++ b/sql/mysql/create_tables.mysql @@ -119,7 +119,7 @@ DROP TABLE IF EXISTS dbmail_messageblks; CREATE TABLE dbmail_messageblks ( messageblk_idnr bigint(21) NOT NULL auto_increment, physmessage_id bigint(21) DEFAULT '0' NOT NULL, - messageblk longtext NOT NULL, + messageblk longblob NOT NULL, blocksize bigint(21) DEFAULT '0' NOT NULL, is_header tinyint(1) DEFAULT '0' NOT NULL, PRIMARY KEY (messageblk_idnr), diff --git a/sql/mysql/create_tables_innoDB.mysql b/sql/mysql/create_tables_innoDB.mysql index d41786e1..b49f8bc8 100644 --- a/sql/mysql/create_tables_innoDB.mysql +++ b/sql/mysql/create_tables_innoDB.mysql @@ -156,7 +156,7 @@ DROP TABLE IF EXISTS dbmail_messageblks; CREATE TABLE dbmail_messageblks ( messageblk_idnr bigint(21) NOT NULL auto_increment, physmessage_id bigint(21) NOT NULL default '0', - messageblk longtext NOT NULL, + messageblk longblob NOT NULL, blocksize bigint(21) NOT NULL default '0', is_header tinyint(1) NOT NULL default '0', PRIMARY KEY (messageblk_idnr), @@ -4,34 +4,34 @@ !_TAG_PROGRAM_NAME Exuberant Ctags // !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ !_TAG_PROGRAM_VERSION 5.5.4 // -A check_dbmail_imapd.c 121;" d file: -APOP_STAMP_SIZE pop3.c 38;" d file: -AUTO_NOTIFY_SENDER pipe.c 58;" d file: -AUTO_NOTIFY_SUBJECT pipe.c 59;" d file: -AcceptedChars imaputil.c /^const char AcceptedChars[] =$/;" v -AcceptedMailboxnameChars imaputil.c /^const char AcceptedMailboxnameChars[] =$/;" v -AcceptedTagChars imaputil.c /^const char AcceptedTagChars[] =$/;" v -BAD misc.c 244;" d file: -BUFLEN dbmail-imapsession.c 56;" d file: -BUFLEN imaputil.c 54;" d file: -COMMAND_SHOW_LEVEL imap4.c 45;" d file: +A check_dbmail_imapd.c 151;" d file: +APOP_STAMP_SIZE pop3.c 28;" d file: +AUTO_NOTIFY_SENDER pipe.c 33;" d file: +AUTO_NOTIFY_SUBJECT pipe.c 34;" d file: +AcceptedChars dm_imaputil.c /^const char AcceptedChars[] =$/;" v +AcceptedMailboxnameChars dm_imaputil.c /^const char AcceptedMailboxnameChars[] =$/;" v +AcceptedTagChars dm_imaputil.c /^const char AcceptedTagChars[] =$/;" v +BAD misc.c 230;" d file: +BUFLEN dbmail-imapsession.c 33;" d file: +BUFLEN dm_imaputil.c 34;" d file: +COMMAND_SHOW_LEVEL imap4.c 29;" d file: ChildStopRequested serverchild.c /^int ChildStopRequested = 0;$/;" v ClearConfig server.c /^void ClearConfig(serverConfig_t * conf)$/;" f CreateChild serverchild.c /^pid_t CreateChild(ChildInfo_t * info)$/;" f CreateSocket server.c /^int CreateSocket(serverConfig_t * conf)$/;" f -D check_dbmail_imapd.c 429;" d file: -DBMAIL_TEMPMBOX dbmail-message.c 61;" d file: -DBPFX db.c 62;" d file: -DBPFX dbmail-imapsession.c 61;" d file: -DBPFX dbmail-message.c 53;" d file: -DBPFX dbmsgbuf.c 42;" d file: -DBPFX dm_search.c 52;" d file: -DB_NTABLES db.c 64;" d file: +D check_dbmail_imapd.c 625;" d file: +DBMAIL_TEMPMBOX dbmail-message.c 40;" d file: +DBPFX db.c 51;" d file: +DBPFX dbmail-imapsession.c 38;" d file: +DBPFX dbmail-message.c 32;" d file: +DBPFX dbmsgbuf.c 33;" d file: +DBPFX dm_search.c 41;" d file: +DB_NTABLES db.c 53;" d file: DB_TABLENAMES db.c /^const char *DB_TABLENAMES[DB_NTABLES] = {$/;" v -DECODE64 misc.c 260;" d file: -DEFAULT_SERVER_TIMEOUT lmtp.c 42;" d file: -DEFAULT_SERVER_TIMEOUT pop3.c 42;" d file: -DEFAULT_SERVER_TIMEOUT timsieve.c 41;" d file: +DECODE64 misc.c 246;" d file: +DEFAULT_SERVER_TIMEOUT lmtp.c 29;" d file: +DEFAULT_SERVER_TIMEOUT pop3.c 32;" d file: +DEFAULT_SERVER_TIMEOUT timsieve.c 30;" d file: DSN_STRINGS_CLASS dsn.c /^static const char * const DSN_STRINGS_CLASS[] = {$/;" v file: DSN_STRINGS_DETAIL_FIVE dsn.c /^static const char * const DSN_STRINGS_DETAIL_FIVE[] = {$/;" v file: DSN_STRINGS_DETAIL_FOUR dsn.c /^static const char * const DSN_STRINGS_DETAIL_FOUR[] = {$/;" v file: @@ -46,15 +46,15 @@ Daemonize lmtpd.c /^void Daemonize()$/;" f Daemonize pop3d.c /^void Daemonize()$/;" f Daemonize timsieved.c /^void Daemonize()$/;" f DelChildSigHandler serverchild.c /^int DelChildSigHandler()$/;" f -EXIT_CODE debug.c 46;" d file: -F1 md5.c 192;" d file: -F2 md5.c 193;" d file: -F3 md5.c 194;" d file: -F4 md5.c 195;" d file: -GREETING timsieve.c 50;" d file: +EXIT_CODE debug.c 38;" d file: +F1 md5.c 183;" d file: +F2 md5.c 184;" d file: +F3 md5.c 185;" d file: +F4 md5.c 186;" d file: +GREETING timsieve.c 39;" d file: GeneralStopRequested server.c /^int GeneralStopRequested = 0;$/;" v GetDBParams config.c /^void GetDBParams(db_param_t * db_params)$/;" f -HEADER_BLOCK_SIZE pipe.c 52;" d file: +HEADER_BLOCK_SIZE pipe.c 27;" d file: IMAPClientHandler imap4.c /^int IMAPClientHandler(clientinfo_t * ci)$/;" f IMAP_COMMANDS imap4.c /^const char *IMAP_COMMANDS[] = {$/;" v IMAP_COMMAND_TYPES imap4.c /^enum IMAP_COMMAND_TYPES { IMAP_COMM_NONE,$/;" g file: @@ -93,37 +93,38 @@ IMAP_COMM_STORE imap4.c /^ IMAP_COMM_SEARCH, IMAP_COMM_FETCH, IMAP_COMM_STORE,$/ IMAP_COMM_SUBSCRIBE imap4.c /^ IMAP_COMM_DELETE, IMAP_COMM_RENAME, IMAP_COMM_SUBSCRIBE,$/;" e enum:IMAP_COMMAND_TYPES file: IMAP_COMM_UID imap4.c /^ IMAP_COMM_COPY, IMAP_COMM_UID, IMAP_COMM_SORT,$/;" e enum:IMAP_COMMAND_TYPES file: IMAP_COMM_UNSUBSCRIBE imap4.c /^ IMAP_COMM_UNSUBSCRIBE, IMAP_COMM_LIST, IMAP_COMM_LSUB,$/;" e enum:IMAP_COMMAND_TYPES file: -IMAP_STANDARD_DATE dbmail-imapsession.c 73;" d file: -IMAP_STANDARD_DATE imaputil.c 82;" d file: -INCOMING_BUFFER_SIZE lmtp.c 39;" d file: -INCOMING_BUFFER_SIZE pop3.c 37;" d file: -INCOMING_BUFFER_SIZE timsieve.c 38;" d file: -INDEX_DELIVERY_MODE main.c 45;" d file: -LISTEX_NOCASE misc.c 707;" d file: -LMTP_TIMEOUT_MSG lmtpd.c 50;" d file: -MAX_ARGS dbmail-imapsession.c 58;" d file: -MAX_ARGS imaputil.c 56;" d file: -MAX_COLUMN_LEN db.c 52;" d file: -MAX_COMM_SIZE pipe.c 55;" d file: -MAX_DATE_LEN db.c 53;" d file: -MAX_ERRORS lmtp.c 45;" d file: -MAX_ERRORS pop3.c 45;" d file: -MAX_ERRORS timsieve.c 44;" d file: -MAX_ERROR_SIZE memblock.c 39;" d file: -MAX_IN_BUFFER lmtp.c 49;" d file: -MAX_IN_BUFFER pop3.c 49;" d file: -MAX_IN_BUFFER timsieve.c 48;" d file: -MAX_LINESIZE dbmail-imapsession.c 53;" d file: -MAX_LINESIZE imap4.c 44;" d file: -MAX_LINESIZE imapcommands.c 60;" d file: -MAX_LINESIZE imaputil.c 51;" d file: -MAX_LINE_SIZE pipe.c 62;" d file: -MAX_RETRIES imapcommands.c 64;" d file: -MAX_U64_STRINGSIZE pipe.c 54;" d file: -MAX_USERID_SIZE pop3.c 39;" d file: -MESSAGEIDSIZE main.c 41;" d file: -MESSAGE_MAX_LINE_SIZE dbmail-message.c 55;" d file: -MSGBUF_WINDOWSIZE dbmsgbuf.c 39;" d file: +IMAP_STANDARD_DATE dbmail-imapsession.c 50;" d file: +IMAP_STANDARD_DATE dm_imaputil.c 62;" d file: +INCOMING_BUFFER_SIZE lmtp.c 26;" d file: +INCOMING_BUFFER_SIZE pop3.c 27;" d file: +INCOMING_BUFFER_SIZE timsieve.c 27;" d file: +INDEX_DELIVERY_MODE main.c 30;" d file: +LEN maintenance.c 29;" d file: +LISTEX_NOCASE misc.c 693;" d file: +LMTP_TIMEOUT_MSG lmtpd.c 32;" d file: +MAX_ARGS dbmail-imapsession.c 35;" d file: +MAX_ARGS dm_imaputil.c 36;" d file: +MAX_COLUMN_LEN db.c 41;" d file: +MAX_COMM_SIZE pipe.c 30;" d file: +MAX_DATE_LEN db.c 42;" d file: +MAX_ERRORS lmtp.c 32;" d file: +MAX_ERRORS pop3.c 35;" d file: +MAX_ERRORS timsieve.c 33;" d file: +MAX_ERROR_SIZE memblock.c 30;" d file: +MAX_IN_BUFFER lmtp.c 36;" d file: +MAX_IN_BUFFER pop3.c 39;" d file: +MAX_IN_BUFFER timsieve.c 37;" d file: +MAX_LINESIZE dbmail-imapsession.c 30;" d file: +MAX_LINESIZE dm_imaputil.c 31;" d file: +MAX_LINESIZE imap4.c 28;" d file: +MAX_LINESIZE imapcommands.c 34;" d file: +MAX_LINE_SIZE pipe.c 37;" d file: +MAX_RETRIES imapcommands.c 38;" d file: +MAX_U64_STRINGSIZE pipe.c 29;" d file: +MAX_USERID_SIZE pop3.c 29;" d file: +MESSAGEIDSIZE main.c 26;" d file: +MESSAGE_MAX_LINE_SIZE dbmail-message.c 34;" d file: +MSGBUF_WINDOWSIZE dbmsgbuf.c 30;" d file: M_BADDATA memblock.c /^enum __M_ERRORS { M_NOERROR, M_NOMEM, M_BADMEM, M_BADDATA, M_BADWHENCE,$/;" e enum:__M_ERRORS file: M_BADMEM memblock.c /^enum __M_ERRORS { M_NOERROR, M_NOMEM, M_BADMEM, M_BADDATA, M_BADWHENCE,$/;" e enum:__M_ERRORS file: M_BADWHENCE memblock.c /^enum __M_ERRORS { M_NOERROR, M_NOMEM, M_BADMEM, M_BADDATA, M_BADWHENCE,$/;" e enum:__M_ERRORS file: @@ -134,40 +135,41 @@ MainSigHandler imapd.c /^void MainSigHandler(int sig, siginfo_t * info UNUSED, v MainSigHandler lmtpd.c /^void MainSigHandler(int sig, siginfo_t * info UNUSED, void *data UNUSED)$/;" f MainSigHandler pop3d.c /^void MainSigHandler(int sig, siginfo_t * info UNUSED, void *data UNUSED)$/;" f MainSigHandler timsieved.c /^void MainSigHandler(int sig, siginfo_t * info UNUSED, void *data UNUSED)$/;" f -N check_dbmail_imapd.c 379;" d file: -NOPAR dbmail-imapsession.c 2333;" d file: -NOPAR dbmail-imapsession.c 2601;" d file: -NORMAL_DELIVERY main.c 42;" d file: -NORMPAR dbmail-imapsession.c 2331;" d file: -NORMPAR dbmail-imapsession.c 2602;" d file: -NR_ACL_FLAGS acl.c 32;" d file: -NULL acl.c 20;" d file: -PERMSTRING_SIZE imapcommands.c 249;" d file: -PNAME imapd.c 46;" d file: -PNAME lmtpd.c 47;" d file: -PNAME main.c 51;" d file: -PNAME pop3d.c 49;" d file: -PNAME timsieved.c 49;" d file: -PNAME user.c 55;" d file: -POP_TIMEOUT_MSG pop3d.c 52;" d file: -P_SIZE pool.c 32;" d file: +N check_dbmail_imapd.c 575;" d file: +NOPAR dbmail-imapsession.c 1701;" d file: +NOPAR dbmail-imapsession.c 1968;" d file: +NORMAL_DELIVERY main.c 27;" d file: +NORMPAR dbmail-imapsession.c 1699;" d file: +NORMPAR dbmail-imapsession.c 1969;" d file: +NR_ACL_FLAGS acl.c 22;" d file: +PERMSTRING_SIZE imapcommands.c 223;" d file: +PNAME imapd.c 29;" d file: +PNAME lmtpd.c 29;" d file: +PNAME main.c 36;" d file: +PNAME maintenance.c 30;" d file: +PNAME pop3d.c 29;" d file: +PNAME timsieved.c 29;" d file: +PNAME user.c 32;" d file: +POP_TIMEOUT_MSG pop3d.c 32;" d file: +P_SIZE pool.c 15;" d file: ParentPID server.c /^pid_t ParentPID = 0;$/;" v ParentSigHandler server.c /^void ParentSigHandler(int sig, siginfo_t * info, void *data)$/;" f PerformChildTask serverchild.c /^int PerformChildTask(ChildInfo_t * info)$/;" f -QUERY_SIZE pipe.c 53;" d file: -READ_CHUNK_SIZE main.c 49;" d file: -REPLYCACHE_TIMEOUT db.c 4312;" d file: -RIGHTPAR dbmail-imapsession.c 2603;" d file: -RING_SIZE pipe.c 56;" d file: +QUERY_SIZE pipe.c 28;" d file: +READ_CHUNK_SIZE main.c 34;" d file: +REPLYCACHE_TIMEOUT db.c 4269;" d file: +RIGHTPAR dbmail-imapsession.c 1970;" d file: +RING_SIZE pipe.c 31;" d file: Restart server.c /^int Restart = 0;$/;" v -SEND_BUF_SIZE dbmail-imapsession.c 57;" d file: -SEND_BUF_SIZE imaputil.c 55;" d file: -SHADOWFILE dbmail-user.c 55;" d file: -SHADOWFILE user.c 54;" d file: -SPECIAL_DELIVERY main.c 43;" d file: -SQL_STANDARD_DATE dbmail-imapsession.c 77;" d file: -SQL_STANDARD_DATE imaputil.c 86;" d file: -SQUAREPAR dbmail-imapsession.c 2332;" d file: +SEND_BUF_SIZE dbmail-imapsession.c 34;" d file: +SEND_BUF_SIZE dm_imaputil.c 35;" d file: +SEND_SPACE dbmail-imapsession.c 678;" d file: +SHADOWFILE dbmail-user.c 31;" d file: +SHADOWFILE user.c 31;" d file: +SPECIAL_DELIVERY main.c 28;" d file: +SQL_STANDARD_DATE dbmail-imapsession.c 54;" d file: +SQL_STANDARD_DATE dm_imaputil.c 66;" d file: +SQUAREPAR dbmail-imapsession.c 1700;" d file: START_TEST check_dbmail_common.c /^START_TEST(test_db_connect)$/;" f START_TEST check_dbmail_common.c /^START_TEST(test_read_config)$/;" f START_TEST check_dbmail_deliver.c /^START_TEST(test_auth_addalias)$/;" f @@ -208,6 +210,9 @@ START_TEST check_dbmail_imapd.c /^START_TEST(test_dm_getguid)$/;" f START_TEST check_dbmail_imapd.c /^START_TEST(test_g_list_join)$/;" f START_TEST check_dbmail_imapd.c /^START_TEST(test_g_list_slices)$/;" f START_TEST check_dbmail_imapd.c /^START_TEST(test_imap_bodyfetch)$/;" f +START_TEST check_dbmail_imapd.c /^START_TEST(test_imap_get_envelope)$/;" f +START_TEST check_dbmail_imapd.c /^START_TEST(test_imap_get_partspec)$/;" f +START_TEST check_dbmail_imapd.c /^START_TEST(test_imap_get_structure)$/;" f START_TEST check_dbmail_imapd.c /^START_TEST(test_imap_session_new)$/;" f START_TEST check_dbmail_imapd.c /^START_TEST(test_listex_match)$/;" f START_TEST check_dbmail_imapd.c /^START_TEST(test_mail_address_build_list)$/;" f @@ -249,17 +254,17 @@ SetParentSigHandler server.c /^int SetParentSigHandler()$/;" f SetTraceLevel config.c /^void SetTraceLevel(const char *service_name)$/;" f StartCliServer server.c /^int StartCliServer(serverConfig_t * conf)$/;" f StartServer server.c /^int StartServer(serverConfig_t * conf)$/;" f -TIMS_TIMEOUT_MSG timsieved.c 52;" d file: +TIMS_TIMEOUT_MSG timsieved.c 32;" d file: TRACE_LEVEL debug.c /^int TRACE_LEVEL = 2; \/* default: error operations *\/$/;" v TRACE_TO_SYSLOG debug.c /^int TRACE_TO_SYSLOG = 1; \/* default: yes *\/$/;" v TRACE_VERBOSE debug.c /^int TRACE_VERBOSE = 0; \/* default: no *\/$/;" v ValidChars dbmail-user.c /^static const char ValidChars[] =$/;" v file: -WRITE_BUFFER_SIZE db.c 80;" d file: -X check_dbmail_imapd.c 378;" d file: -X check_dbmail_server.c 86;" d file: -Y check_dbmail_imapd.c 377;" d file: -Y check_dbmail_server.c 87;" d file: -_GNU_SOURCE imapcommands.c 32;" d file: +WRITE_BUFFER_SIZE db.c 69;" d file: +X check_dbmail_imapd.c 574;" d file: +X check_dbmail_server.c 72;" d file: +Y check_dbmail_imapd.c 573;" d file: +Y check_dbmail_server.c 73;" d file: +_GNU_SOURCE imapcommands.c 30;" d file: __M_ERRORS memblock.c /^enum __M_ERRORS { M_NOERROR, M_NOMEM, M_BADMEM, M_BADDATA, M_BADWHENCE,$/;" g file: __debug_dumpallocs debug.c /^void __debug_dumpallocs()$/;" f __debug_free debug.c /^void __debug_free(void *ptr, const char *fname, int linenr)$/;" f @@ -273,7 +278,6 @@ __m_error_str memblock.c /^char __m_error_str[MAX_ERROR_SIZE];$/;" v _dm_getopt_internal dm_getopt.c /^int _dm_getopt_internal(int argc, char * argv[], const char *shortopts,$/;" f _fetch_full dbmail-message.c /^static struct DbmailMessage * _fetch_full(struct DbmailMessage *self) $/;" f file: _fetch_head dbmail-message.c /^static struct DbmailMessage * _fetch_head(struct DbmailMessage *self)$/;" f file: -_get_crlf_encoded dbmail-message.c /^static GMimeStream * _get_crlf_encoded(struct DbmailMessage *self)$/;" f file: _header_cache dbmail-message.c /^void _header_cache(const char *header, const char *value, gpointer user_data)$/;" f _header_get_id dbmail-message.c /^static int _header_get_id(struct DbmailMessage *self, const char *header, u64_t *id)$/;" f file: _ic_append imapcommands.c /^int _ic_append(struct ImapSession *self)$/;" f @@ -309,29 +313,29 @@ _ic_store imapcommands.c /^int _ic_store(struct ImapSession *self)$/;" f _ic_subscribe imapcommands.c /^int _ic_subscribe(struct ImapSession *self)$/;" f _ic_uid imapcommands.c /^int _ic_uid(struct ImapSession *self)$/;" f _ic_unsubscribe imapcommands.c /^int _ic_unsubscribe(struct ImapSession *self)$/;" f +_imap_append_alist_as_plist dm_imaputil.c /^static GList * _imap_append_alist_as_plist(GList *list, InternetAddressList *ialist)$/;" f file: _imap_cache_update dbmail-imapsession.c /^static u64_t _imap_cache_update(struct ImapSession *self, message_filter_t filter)$/;" f file: -_imap_get_addresses dbmail-imapsession.c /^static GList * _imap_get_addresses(struct mime_record *mr)$/;" f file: -_imap_get_envelope dbmail-imapsession.c /^static GList * _imap_get_envelope(struct dm_list *rfcheader)$/;" f file: -_imap_get_mime_parameters dbmail-imapsession.c /^static GList * _imap_get_mime_parameters(struct mime_record *mr, int force_subtype, int only_extension)$/;" f file: -_imap_get_structure dbmail-imapsession.c /^GList * _imap_get_structure(mime_message_t * msg, int show_extension_data)$/;" f _imap_session_fetch_parse_octet_range dbmail-imapsession.c /^static int _imap_session_fetch_parse_octet_range(struct ImapSession *self, int idx) $/;" f file: _imap_session_fetch_parse_partspec dbmail-imapsession.c /^static int _imap_session_fetch_parse_partspec(struct ImapSession *self, int idx)$/;" f file: _imap_show_body_section dbmail-imapsession.c /^static int _imap_show_body_section(body_fetch_t *bodyfetch, gpointer data) {$/;" f file: _imap_show_body_sections dbmail-imapsession.c /^static void _imap_show_body_sections(struct ImapSession *self) {$/;" f file: -_imapdate imaputil.c /^char _imapdate[IMAP_INTERNALDATE_LEN] = IMAP_STANDARD_DATE;$/;" v +_imapdate dm_imaputil.c /^char _imapdate[IMAP_INTERNALDATE_LEN] = IMAP_STANDARD_DATE;$/;" v _map_headers dbmail-message.c /^static void _map_headers(struct DbmailMessage *self) $/;" f file: _message_insert dbmail-message.c /^int _message_insert(struct DbmailMessage *self, $/;" f _msg_fetch_inited dbmsgbuf.c /^static int _msg_fetch_inited = 0;$/;" v file: -_msgrow_idx dbmsgbuf.c /^static unsigned _msgrow_idx = 0;$/;" v file: _register_header dbmail-message.c /^static void _register_header(const char *header, const char *value, gpointer user_data)$/;" f file: _register_header mime.c /^static void _register_header(const char *field, const char *value, gpointer mimelist)$/;" f file: _retrieve dbmail-message.c /^static struct DbmailMessage * _retrieve(struct DbmailMessage *self, char *query_template)$/;" f file: _set_content dbmail-message.c /^static void _set_content(struct DbmailMessage *self, const GString *content)$/;" f file: _set_content_from_stream dbmail-message.c /^static void _set_content_from_stream(struct DbmailMessage *self, GMimeStream *stream, int type)$/;" f file: -_sqldate imaputil.c /^char _sqldate[SQL_INTERNALDATE_LEN + 1] = SQL_STANDARD_DATE;$/;" v +_sqldate dm_imaputil.c /^char _sqldate[SQL_INTERNALDATE_LEN + 1] = SQL_STANDARD_DATE;$/;" v _strip_blob_prefix misc.c /^static void _strip_blob_prefix(char *subject)$/;" f file: _strip_refwd misc.c /^static void _strip_refwd(char *subject) $/;" f file: _strip_sub_leader misc.c /^static void _strip_sub_leader(char *subject)$/;" f file: +_structure_part_handle_part dm_imaputil.c /^void _structure_part_handle_part(GMimeObject *part, gpointer data, gboolean extension)$/;" f +_structure_part_message_rfc822 dm_imaputil.c /^void _structure_part_message_rfc822(GMimeObject *part, gpointer data, gboolean extension)$/;" f +_structure_part_multipart dm_imaputil.c /^void _structure_part_multipart(GMimeObject *part, gpointer data, gboolean extension)$/;" f +_structure_part_text dm_imaputil.c /^void _structure_part_text(GMimeObject *part, gpointer data, gboolean extension)$/;" f acl_change_rights acl.c /^acl_change_rights(u64_t userid, u64_t mboxid, const char *rightsstring,$/;" f acl_delete_acl acl.c /^int acl_delete_acl(u64_t userid, u64_t mboxid)$/;" f acl_get_acl acl.c /^char *acl_get_acl(u64_t mboxid)$/;" f @@ -352,27 +356,27 @@ addto_btree_curr dm_search.c /^void addto_btree_curr(sortitems_t ** root, char * base64_decode misc.c /^char **base64_decode(char *str, size_t len)$/;" f base64_decode_internal misc.c /^int base64_decode_internal(const char *in, size_t inlen, size_t maxlen,$/;" f base64_free misc.c /^void base64_free(char **ret)$/;" f -base64decode imaputil.c /^void base64decode(char *in, char *out)$/;" f -base64encode imaputil.c /^void base64encode(char *in, char *out)$/;" f -base64encodestring imaputil.c /^char base64encodestring[] =$/;" v +base64decode dm_imaputil.c /^void base64decode(char *in, char *out)$/;" f +base64encode dm_imaputil.c /^void base64encode(char *in, char *out)$/;" f +base64encodestring dm_imaputil.c /^char base64encodestring[] =$/;" v base64val misc.c /^static const char base64val[] = {$/;" v file: bgetpwent dbmail-user.c /^char *bgetpwent(const char *filename, const char *name)$/;" f -binary_search imaputil.c /^int binary_search(const u64_t * array, unsigned arraysize, u64_t key,$/;" f +binary_search dm_imaputil.c /^int binary_search(const u64_t * array, unsigned arraysize, u64_t key,$/;" f build_args_array_ext dbmail-imapsession.c /^char **build_args_array_ext(const char *originalString, clientinfo_t * ci)$/;" f -build_imap_search imaputil.c /^int build_imap_search(char **search_keys, struct dm_list *sl, int *idx, int sorted)$/;" f -build_set imaputil.c /^void build_set(unsigned int *set, unsigned int setlen, char *cset)$/;" f -build_uid_set imaputil.c /^void build_uid_set(unsigned int *set, unsigned int setlen, char *cset,$/;" f +build_imap_search dm_imaputil.c /^int build_imap_search(char **search_keys, struct dm_list *sl, int *idx, int sorted)$/;" f +build_set dm_imaputil.c /^void build_set(unsigned int *set, unsigned int setlen, char *cset)$/;" f +build_uid_set dm_imaputil.c /^void build_uid_set(unsigned int *set, unsigned int setlen, char *cset,$/;" f byteReverse md5.c /^void byteReverse(unsigned char *buf, unsigned longs)$/;" f -byteReverse md5.c 57;" d file: +byteReverse md5.c 48;" d file: cached_msg imap4.c /^cache_t cached_msg;$/;" v cget_salt dbmail-user.c /^char *cget_salt()$/;" f char2date_str db.c /^char *char2date_str(const char *date)$/;" f -check_date imaputil.c /^int check_date(const char *date)$/;" f -check_msg_set imaputil.c /^int check_msg_set(const char *s)$/;" f +check_date dm_imaputil.c /^int check_date(const char *date)$/;" f +check_msg_set dm_imaputil.c /^int check_msg_set(const char *s)$/;" f check_state_and_args dbmail-imapsession.c /^int check_state_and_args(struct ImapSession * self, const char *command, int minargs, int maxargs, int state)$/;" f -checkchars imaputil.c /^int checkchars(const char *s)$/;" f -checkmailboxname imaputil.c /^int checkmailboxname(const char *s)$/;" f -checktag imaputil.c /^int checktag(const char *s)$/;" f +checkchars dm_imaputil.c /^int checkchars(const char *s)$/;" f +checkmailboxname dm_imaputil.c /^int checkmailboxname(const char *s)$/;" f +checktag dm_imaputil.c /^int checktag(const char *s)$/;" f child_reg_connected pool.c /^void child_reg_connected()$/;" f child_reg_disconnected pool.c /^void child_reg_disconnected()$/;" f child_register pool.c /^int child_register()$/;" f @@ -383,11 +387,11 @@ cidr_free dm_cidr.c /^void cidr_free(struct cidrfilter *self)$/;" f cidr_match dm_cidr.c /^int cidr_match(struct cidrfilter *base, struct cidrfilter *test)$/;" f cidr_new dm_cidr.c /^struct cidrfilter * cidr_new(const char *str)$/;" f cidr_repr dm_cidr.c /^int cidr_repr(struct cidrfilter *self) $/;" f -clarify_data imaputil.c /^void clarify_data(char *str)$/;" f +clarify_data dm_imaputil.c /^void clarify_data(char *str)$/;" f client serverchild.c /^clientinfo_t client;$/;" v client_close serverchild.c /^void client_close(void)$/;" f -close_cache imaputil.c /^void close_cache()$/;" f -combine_sets imaputil.c /^void combine_sets(unsigned int *dest, unsigned int *sec, int setlen, int type)$/;" f +close_cache dm_imaputil.c /^void close_cache()$/;" f +combine_sets dm_imaputil.c /^void combine_sets(unsigned int *dest, unsigned int *sec, int setlen, int type)$/;" f commands lmtp.c /^static const char *const commands[] = {$/;" v file: commands pop3.c /^const char *commands[] = {$/;" v commands timsieve.c /^static const char *commands[] = {$/;" v file: @@ -415,8 +419,8 @@ create_unique_id misc.c /^void create_unique_id(char *target, u64_t message_idnr create_unix_socket server.c /^static int create_unix_socket(serverConfig_t * conf)$/;" f file: csalt dbmail-user.c /^static char csalt[] = "........";$/;" v file: date2char_str db.c /^char *date2char_str(const char *column)$/;" f -date_imap2sql imaputil.c /^char *date_imap2sql(const char *imapdate)$/;" f -date_sql2imap imaputil.c /^char *date_sql2imap(const char *sqldate)$/;" f +date_imap2sql dm_imaputil.c /^char *date_imap2sql(const char *imapdate)$/;" f +date_sql2imap dm_imaputil.c /^char *date_sql2imap(const char *sqldate)$/;" f db_acl_create_acl db.c /^static int db_acl_create_acl(u64_t userid, u64_t mboxid)$/;" f file: db_acl_delete_acl db.c /^int db_acl_delete_acl(u64_t userid, u64_t mboxid)$/;" f db_acl_get_identifier db.c /^int db_acl_get_identifier(u64_t mboxid, struct dm_list *identifier_list)$/;" f @@ -424,7 +428,6 @@ db_acl_has_acl db.c /^static int db_acl_has_acl(u64_t userid, u64_t mboxid)$/;" db_acl_has_right db.c /^int db_acl_has_right(u64_t userid, u64_t mboxid, const char *right_flag)$/;" f db_acl_set_right db.c /^int db_acl_set_right(u64_t userid, u64_t mboxid, const char *right_flag,$/;" f db_activate_sievescript db.c /^int db_activate_sievescript(u64_t user_idnr, char *scriptname)$/;" f -db_add_mime_children rfcmsg.c /^int db_add_mime_children(struct dm_list *brothers, char *splitbound,$/;" f db_add_quotum_used db.c /^int db_add_quotum_used(u64_t user_idnr, u64_t add_size)$/;" f db_add_sievescript db.c /^int db_add_sievescript(u64_t user_idnr, char *scriptname, char *script)$/;" f db_begin_transaction db.c /^int db_begin_transaction()$/;" f @@ -450,7 +453,6 @@ db_delete_physmessage db.c /^int db_delete_physmessage(u64_t physmessage_id)$/;" db_delete_sievescript db.c /^int db_delete_sievescript(u64_t user_idnr, char *scriptname)$/;" f db_deleted_count db.c /^int db_deleted_count(u64_t * affected_rows)$/;" f db_deleted_purge db.c /^int db_deleted_purge(u64_t * affected_rows)$/;" f -db_dump_range dbmsgbuf.c /^long db_dump_range(MEM * outmem, db_pos_t start,$/;" f db_empty_mailbox db.c /^int db_empty_mailbox(u64_t user_idnr)$/;" f db_exec_search dm_search.c /^int db_exec_search(mime_message_t * msg, search_key_t * sk, u64_t msg_idnr)$/;" f db_expunge db.c /^int db_expunge(u64_t mailbox_idnr, u64_t user_idnr,$/;" f @@ -497,7 +499,7 @@ db_icheck_null_messages db.c /^int db_icheck_null_messages(struct dm_list *lost_ db_icheck_null_physmessages db.c /^int db_icheck_null_physmessages(struct dm_list *lost_list)$/;" f db_imap_append_msg db.c /^int db_imap_append_msg(const char *msgdata, u64_t datalen UNUSED,$/;" f db_init_fetch dbmsgbuf.c /^struct DbmailMessage * db_init_fetch(u64_t msg_idnr, int filter)$/;" f -db_init_fetch_messageblks dbmsgbuf.c /^int db_init_fetch_messageblks(u64_t msg_idnr, int filter)$/;" f +db_init_fetch_message dbmsgbuf.c /^struct DbmailMessage * db_init_fetch_message(u64_t msg_idnr, int filter)$/;" f db_insert_message_block db.c /^int db_insert_message_block(const char *block, u64_t block_size,$/;" f db_insert_message_block_physmessage db.c /^int db_insert_message_block_physmessage(const char *block,$/;" f db_insert_physmessage db.c /^int db_insert_physmessage(u64_t * physmessage_id)$/;" f @@ -509,9 +511,8 @@ db_log_ip db.c /^int db_log_ip(const char *ip)$/;" f db_mailbox_msg_match db.c /^int db_mailbox_msg_match(u64_t mailbox_idnr, u64_t msg_idnr)$/;" f db_message_set_unique_id db.c /^int db_message_set_unique_id(u64_t message_idnr, const char *unique_id)$/;" f db_movemsg db.c /^int db_movemsg(u64_t mailbox_to, u64_t mailbox_from)$/;" f -db_msgdump rfcmsg.c /^int db_msgdump(mime_message_t * msg, u64_t msguid, int level)$/;" f +db_new_msg rfcmsg.c /^mime_message_t * db_new_msg(void)$/;" f db_noinferiors db.c /^int db_noinferiors(u64_t mailbox_idnr)$/;" f -db_parse_as_text rfcmsg.c /^int db_parse_as_text(mime_message_t * msg)$/;" f db_physmessage_set_sizes db.c /^int db_physmessage_set_sizes(u64_t physmessage_id, u64_t message_size,$/;" f db_removemsg db.c /^int db_removemsg(u64_t user_idnr, u64_t mailbox_idnr)$/;" f db_replace_sievescript db.c /^int db_replace_sievescript(u64_t user_idnr, char *scriptname, char *script)$/;" f @@ -521,7 +522,7 @@ db_reverse_msg rfcmsg.c /^static void db_reverse_msg(mime_message_t * msg)$/;" f db_rollback_transaction db.c /^int db_rollback_transaction()$/;" f db_search dm_search.c /^int db_search(unsigned int *rset, unsigned setlen, search_key_t * sk, mailbox_t * mb)$/;" f db_search_parsed dm_search.c /^int db_search_parsed(unsigned int *rset, unsigned int setlen,$/;" f -db_search_range dm_search.c /^int db_search_range(db_pos_t start, db_pos_t end,$/;" f +db_search_range dm_search.c /^int db_search_range(db_pos_t start, db_pos_t end, const char *key, u64_t msg_idnr)$/;" f db_send_message_lines db.c /^int db_send_message_lines(void *fstream, u64_t message_idnr,$/;" f db_session_cleanup db.c /^void db_session_cleanup(PopSession_t * session_ptr)$/;" f db_set_deleted db.c /^int db_set_deleted(u64_t * affected_rows)$/;" f @@ -538,12 +539,12 @@ db_set_sievescript_quota db.c /^int db_set_sievescript_quota(u64_t user_idnr, u6 db_setmailboxname db.c /^int db_setmailboxname(u64_t mailbox_idnr, const char *name)$/;" f db_setselectable db.c /^int db_setselectable(u64_t mailbox_idnr, int select_value)$/;" f db_sort_parsed dm_search.c /^int db_sort_parsed(unsigned int *rset, unsigned int setlen,$/;" f -db_start_msg rfcmsg.c /^int db_start_msg(mime_message_t * msg, char *stopbound, int *level, int maxlevel)$/;" f +db_start_msg rfcmsg.c /^int db_start_msg(struct DbmailMessage *message, mime_message_t * msg, char *stopbound, int *level, int maxlevel)$/;" f db_subscribe db.c /^int db_subscribe(u64_t mailbox_idnr, u64_t user_idnr)$/;" f db_subtract_quotum_used db.c /^int db_subtract_quotum_used(u64_t user_idnr, u64_t sub_size)$/;" f db_unsubscribe db.c /^int db_unsubscribe(u64_t mailbox_idnr, u64_t user_idnr)$/;" f db_update_message db.c /^int db_update_message(u64_t message_idnr, const char *unique_id,$/;" f -db_update_msgbuf dbmsgbuf.c /^int db_update_msgbuf(int minlen)$/;" f +db_update_msgbuf dbmsgbuf.c /^int db_update_msgbuf(int minlen UNUSED)$/;" f db_update_pop db.c /^int db_update_pop(PopSession_t * session_ptr)$/;" f db_use_usermap db.c /^int db_use_usermap(void)$/;" f db_user_create db.c /^int db_user_create(const char *username, const char *password, const char *enctype,$/;" f @@ -558,9 +559,9 @@ dbmail_common_suite check_dbmail_common.c /^Suite *dbmail_common_suite(void)$/;" dbmail_common_suite check_dbmail_user.c /^Suite *dbmail_common_suite(void)$/;" f dbmail_common_suite check_dbmail_util.c /^Suite *dbmail_common_suite(void)$/;" f dbmail_deliver_suite check_dbmail_deliver.c /^Suite *dbmail_deliver_suite(void)$/;" f -dbmail_imap_astring_as_string imaputil.c /^char *dbmail_imap_astring_as_string(const char *s)$/;" f -dbmail_imap_plist_as_string imaputil.c /^char *dbmail_imap_plist_as_string(GList * list)$/;" f -dbmail_imap_plist_free imaputil.c /^void dbmail_imap_plist_free(GList *l)$/;" f +dbmail_imap_astring_as_string dm_imaputil.c /^char *dbmail_imap_astring_as_string(const char *s)$/;" f +dbmail_imap_plist_as_string dm_imaputil.c /^char *dbmail_imap_plist_as_string(GList * list)$/;" f +dbmail_imap_plist_free dm_imaputil.c /^void dbmail_imap_plist_free(GList *l)$/;" f dbmail_imap_session_bodyfetch_free dbmail-imapsession.c /^void dbmail_imap_session_bodyfetch_free(struct ImapSession *self) $/;" f dbmail_imap_session_bodyfetch_get_last dbmail-imapsession.c /^body_fetch_t * dbmail_imap_session_bodyfetch_get_last(struct ImapSession *self) $/;" f dbmail_imap_session_bodyfetch_get_last_argcnt dbmail-imapsession.c /^int dbmail_imap_session_bodyfetch_get_last_argcnt(struct ImapSession *self) $/;" f @@ -605,6 +606,7 @@ dbmail_imap_session_set_state dbmail-imapsession.c /^int dbmail_imap_session_set dbmail_mailbox_free dbmail-mailbox.c /^void * dbmail_mailbox_free(struct DbmailMailbox *self)$/;" f dbmail_mailbox_new dbmail-mailbox.c /^struct DbmailMailbox * dbmail_mailbox_new(u64_t mailbox_idnr)$/;" f dbmail_mailbox_orderedsubject dbmail-mailbox.c /^GList * dbmail_mailbox_orderedsubject(struct DbmailMailbox *self)$/;" f +dbmail_mailbox_suite check_dbmail_mailbox.c /^Suite *dbmail_mailbox_suite(void)$/;" f dbmail_message_body_to_string dbmail-message.c /^gchar * dbmail_message_body_to_string(struct DbmailMessage *self)$/;" f dbmail_message_cache_ccfield dbmail-message.c /^void dbmail_message_cache_ccfield(struct DbmailMessage *self)$/;" f dbmail_message_cache_datefield dbmail-message.c /^void dbmail_message_cache_datefield(struct DbmailMessage *self)$/;" f @@ -614,14 +616,13 @@ dbmail_message_cache_replytofield dbmail-message.c /^void dbmail_message_cache_r dbmail_message_cache_subjectfield dbmail-message.c /^void dbmail_message_cache_subjectfield(struct DbmailMessage *self)$/;" f dbmail_message_cache_tofield dbmail-message.c /^void dbmail_message_cache_tofield(struct DbmailMessage *self)$/;" f dbmail_message_free dbmail-message.c /^void dbmail_message_free(struct DbmailMessage *self)$/;" f -dbmail_message_get_body_size dbmail-message.c /^size_t dbmail_message_get_body_size(struct DbmailMessage *self)$/;" f +dbmail_message_get_body_size dbmail-message.c /^size_t dbmail_message_get_body_size(struct DbmailMessage *self, gboolean crlf)$/;" f dbmail_message_get_class dbmail-message.c /^int dbmail_message_get_class(struct DbmailMessage *self)$/;" f -dbmail_message_get_hdrs_size dbmail-message.c /^size_t dbmail_message_get_hdrs_size(struct DbmailMessage *self)$/;" f +dbmail_message_get_hdrs_size dbmail-message.c /^size_t dbmail_message_get_hdrs_size(struct DbmailMessage *self, gboolean crlf)$/;" f dbmail_message_get_header dbmail-message.c /^gchar * dbmail_message_get_header(struct DbmailMessage *self, const char *header)$/;" f dbmail_message_get_internal_date dbmail-message.c /^gchar * dbmail_message_get_internal_date(struct DbmailMessage *self)$/;" f dbmail_message_get_physid dbmail-message.c /^u64_t dbmail_message_get_physid(struct DbmailMessage *self)$/;" f -dbmail_message_get_rfcsize dbmail-message.c /^size_t dbmail_message_get_rfcsize(struct DbmailMessage *self) $/;" f -dbmail_message_get_size dbmail-message.c /^size_t dbmail_message_get_size(struct DbmailMessage *self)$/;" f +dbmail_message_get_size dbmail-message.c /^size_t dbmail_message_get_size(struct DbmailMessage *self, gboolean crlf)$/;" f dbmail_message_hdrs_to_string dbmail-message.c /^gchar * dbmail_message_hdrs_to_string(struct DbmailMessage *self)$/;" f dbmail_message_headers_cache dbmail-message.c /^int dbmail_message_headers_cache(struct DbmailMessage *self)$/;" f dbmail_message_init_with_stream dbmail-message.c /^struct DbmailMessage * dbmail_message_init_with_stream(struct DbmailMessage *self, GMimeStream *stream, int type)$/;" f @@ -635,7 +636,7 @@ dbmail_message_set_internal_date dbmail-message.c /^void dbmail_message_set_inte dbmail_message_set_physid dbmail-message.c /^void dbmail_message_set_physid(struct DbmailMessage *self, u64_t physid)$/;" f dbmail_message_store dbmail-message.c /^int dbmail_message_store(struct DbmailMessage *self)$/;" f dbmail_message_suite check_dbmail_message.c /^Suite *dbmail_message_suite(void)$/;" f -dbmail_message_to_string dbmail-message.c /^gchar * dbmail_message_to_string(struct DbmailMessage *self, gboolean crlf) $/;" f +dbmail_message_to_string dbmail-message.c /^gchar * dbmail_message_to_string(struct DbmailMessage *self) $/;" f dbmail_server_suite check_dbmail_server.c /^Suite *dbmail_server_suite(void)$/;" f dbmail_suite check_dbmail_imapd.c /^Suite *dbmail_suite(void)$/;" f debug_mem debug.c /^struct debug_mem {$/;" s file: @@ -720,16 +721,16 @@ dsnuser_resolve_list dsn.c /^int dsnuser_resolve_list(struct dm_list *deliveries dsnuser_worstcase_int dsn.c /^delivery_status_t dsnuser_worstcase_int(int ok, int temp, int fail, int fail_quota)$/;" f dsnuser_worstcase_list dsn.c /^delivery_status_t dsnuser_worstcase_list(struct dm_list * deliveries)$/;" f dsnusers main.c /^struct dm_list dsnusers; \/* list of deliver_to_user_t structs *\/$/;" v -dumpsearch imaputil.c /^void dumpsearch(search_key_t * sk, int level)$/;" f +dumpsearch dm_imaputil.c /^void dumpsearch(search_key_t * sk, int level)$/;" f element_new list.c /^static struct element *element_new(void)$/;" f file: -envelope_items imaputil.c /^const char *envelope_items[] = {$/;" v -err_out_stream debug.c 45;" d file: +envelope_items dm_imaputil.c /^const char *envelope_items[] = {$/;" v +err_out_stream debug.c 37;" d file: execute_auto_ran pipe.c /^static int execute_auto_ran(u64_t useridnr, struct dm_list *headerfields)$/;" f file: find_bounded misc.c /^int find_bounded(char *value, char left, char right, char **retchar,$/;" f find_time maintenance.c /^void find_time(char *timestr, const char *timespec)$/;" f fname debug.c /^ char fname[200];$/;" m struct:debug_mem file: forward forward.c /^int forward(u64_t msgidnr, struct dm_list *targets, const char *from,$/;" f -free_searchlist imaputil.c /^void free_searchlist(struct dm_list *sl)$/;" f +free_searchlist dm_imaputil.c /^void free_searchlist(struct dm_list *sl)$/;" f from lmtp.c /^static struct dm_list from, rcpt;$/;" v file: func_memtst debug.c /^void func_memtst(const char *filename, int line, int tst)$/;" f g_list_append_printf misc.c /^GList * g_list_append_printf(GList * list, char * format, ...)$/;" f @@ -739,7 +740,7 @@ g_list_slices list.c /^GList *g_list_slices(GList *list, unsigned limit)$/;" f g_string_split misc.c /^GList * g_string_split(GString * string, char * sep)$/;" f gdm_md5_final md5.c /^void gdm_md5_final(unsigned char digest[16], struct GdmMD5Context *ctx)$/;" f gdm_md5_init md5.c /^void gdm_md5_init(struct GdmMD5Context *ctx)$/;" f -gdm_md5_step md5.c 198;" d file: +gdm_md5_step md5.c 189;" d file: gdm_md5_transform md5.c /^void gdm_md5_transform(uint32 buf[4], uint32 const in[16])$/;" f gdm_md5_update md5.c /^gdm_md5_update(struct GdmMD5Context *ctx, unsigned char const *buf,$/;" f getKey pool.c /^int getKey(pid_t pid)$/;" f @@ -750,30 +751,42 @@ get_config imapd.c /^void get_config(serverConfig_t *config)$/;" f get_config lmtpd.c /^void get_config(serverConfig_t *config) $/;" f get_config pop3d.c /^void get_config(serverConfig_t *config)$/;" f get_count_on check_dbmail_imapd.c /^unsigned int get_count_on(unsigned int * set, unsigned int setlen) {$/;" f +get_crlf_encoded dbmail-message.c /^gchar * get_crlf_encoded(gchar *string)$/;" f get_dumpsize dbmail-imapsession.c /^u64_t get_dumpsize(body_fetch_t *bodyfetch, u64_t dumpsize) $/;" f get_first_user_idnr check_dbmail_deliver.c /^u64_t get_first_user_idnr(void)$/;" f +get_first_user_idnr check_dbmail_mailbox.c /^static u64_t get_first_user_idnr(void)$/;" f file: get_idle_spare pool.c /^pid_t get_idle_spare()$/;" f -get_part_by_num imaputil.c /^mime_message_t *get_part_by_num(mime_message_t * msg, const char *part)$/;" f +get_param_list dm_imaputil.c /^static void get_param_list(gpointer key, gpointer value, gpointer data)$/;" f file: +get_part_by_num dm_imaputil.c /^mime_message_t *get_part_by_num(mime_message_t * msg, const char *part)$/;" f has_errors maintenance.c /^int has_errors = 0;$/;" v -haystack_find imaputil.c /^int haystack_find(int haystacklen, char **haystack, const char *needle)$/;" f +haystack_find dm_imaputil.c /^int haystack_find(int haystacklen, char **haystack, const char *needle)$/;" f imap_acl_pre_administer imapcommands.c /^static int imap_acl_pre_administer(const char *mailboxname,$/;" f file: +imap_append_disposition_as_string dm_imaputil.c /^static GList * imap_append_disposition_as_string(GList *list, GMimeObject *part)$/;" f file: +imap_append_hash_as_string dm_imaputil.c /^static GList * imap_append_hash_as_string(GList *list, GHashTable *hash)$/;" f file: +imap_append_header_as_string dm_imaputil.c /^static GList * imap_append_header_as_string(GList *list, GMimeObject *part, const char *header)$/;" f file: imap_before_smtp check_dbmail_deliver.c /^int imap_before_smtp = 0;$/;" v imap_before_smtp check_dbmail_imapd.c /^int imap_before_smtp = 0;$/;" v +imap_before_smtp check_dbmail_mailbox.c /^int imap_before_smtp = 0;$/;" v imap_before_smtp check_dbmail_server.c /^int imap_before_smtp = 0;$/;" v imap_before_smtp imapd.c /^int imap_before_smtp = 0;$/;" v imap_flag_desc imapcommands.c /^const char *imap_flag_desc[IMAP_NFLAGS] = {$/;" v imap_flag_desc_escaped imapcommands.c /^const char *imap_flag_desc_escaped[IMAP_NFLAGS] = {$/;" v +imap_get_envelope dm_imaputil.c /^GList * imap_get_envelope(GMimeMessage *message)$/;" f +imap_get_partspec dm_imaputil.c /^char * imap_get_partspec(const GMimeObject *message, const char *partspec) $/;" f +imap_get_structure dm_imaputil.c /^GList * imap_get_structure(GMimeMessage *message, gboolean extension) $/;" f imap_handler_functions imap4.c /^const IMAP_COMMAND_HANDLER imap_handler_functions[] = {$/;" v -init_cache imaputil.c /^int init_cache()$/;" f +imap_part_get_sizes dm_imaputil.c /^static void imap_part_get_sizes(GMimeObject *part, size_t * size, size_t * lines)$/;" f file: +init_cache dm_imaputil.c /^int init_cache()$/;" f init_testuser1 check_dbmail_deliver.c /^void init_testuser1(void) $/;" f +init_testuser1 check_dbmail_imapd.c /^void init_testuser1(void) $/;" f +init_testuser1 check_dbmail_mailbox.c /^static void init_testuser1(void) $/;" f file: insert_address_cache dbmail-message.c /^static void insert_address_cache(u64_t physid, const char *field, InternetAddressList *ialist)$/;" f file: insert_field_cache dbmail-message.c /^static void insert_field_cache(u64_t physid, const char *field, const char *value)$/;" f file: insert_messages pipe.c /^int insert_messages(struct DbmailMessage *message, $/;" f -invert_set imaputil.c /^void invert_set(unsigned int *set, int setlen)$/;" f -is_end_of_header mime.c /^static int is_end_of_header(const char *s)$/;" f file: -is_textplain imaputil.c /^int is_textplain(struct dm_list *hdr)$/;" f +invert_set dm_imaputil.c /^void invert_set(unsigned int *set, int setlen)$/;" f +is_textplain dm_imaputil.c /^int is_textplain(struct dm_list *hdr)$/;" f is_valid dbmail-user.c /^int is_valid(const char *str)$/;" f -item_desc imaputil.c /^const char *item_desc[] = {$/;" v +item_desc dm_imaputil.c /^const char *item_desc[] = {$/;" v itoa misc.c /^char *itoa(int i)$/;" f linenr debug.c /^ int linenr;$/;" m struct:debug_mem file: list_is_lsub imapcommands.c /^int list_is_lsub = 0;$/;" v @@ -784,12 +797,13 @@ lmtp_error lmtp.c /^int lmtp_error(PopSession_t * session, void *stream,$/;" f lmtp_handle_connection lmtp.c /^int lmtp_handle_connection(clientinfo_t * ci)$/;" f lmtp_init lmtp.c /^void lmtp_init(PopSession_t *session) $/;" f lmtp_reset lmtp.c /^int lmtp_reset(PopSession_t * session)$/;" f -mail_address_build_list mime.c /^int mail_address_build_list(char *scan_for_field, struct dm_list *targetlist,$/;" f +mail_address_build_list mime.c /^int mail_address_build_list(const char *scan_for_field, struct dm_list *targetlist,$/;" f mailbox_add_namespace misc.c /^char *mailbox_add_namespace(const char *mailbox_name, u64_t owner_idnr,$/;" f mailbox_remove_namespace misc.c /^const char *mailbox_remove_namespace(const char *fq_name)$/;" f main check_dbmail_common.c /^int main(void)$/;" f main check_dbmail_deliver.c /^int main(void)$/;" f main check_dbmail_imapd.c /^int main(void)$/;" f +main check_dbmail_mailbox.c /^int main(void)$/;" f main check_dbmail_message.c /^int main(void)$/;" f main check_dbmail_server.c /^int main(void)$/;" f main check_dbmail_user.c /^int main(void)$/;" f @@ -816,19 +830,19 @@ manage_spare_children pool.c /^void manage_spare_children()$/;" f manage_start_children pool.c /^void manage_start_children()$/;" f manage_start_cli_server serverchild.c /^int manage_start_cli_server(ChildInfo_t * info)$/;" f manage_stop_children pool.c /^void manage_stop_children()$/;" f -max misc.c 42;" d file: -max misc.c 43;" d file: +max misc.c 28;" d file: +max misc.c 29;" d file: mclose memblock.c /^void mclose(MEM ** m)$/;" f merror memblock.c /^char *merror()$/;" f -mime_fetch_headers mime.c /^int mime_fetch_headers(const char *datablock, struct dm_list *mimelist) $/;" f +mime_fetch_headers mime.c /^struct DbmailMessage * mime_fetch_headers(struct DbmailMessage *message, struct dm_list *mimelist) $/;" f mime_findfield mime.c /^void mime_findfield(const char *fname, struct dm_list *mimelist,$/;" f -mime_readheader mime.c /^int mime_readheader(const char *datablock, u64_t * blkidx, struct dm_list *mimelist,$/;" f -mime_unwrap imaputil.c /^int mime_unwrap(char *to, const char *from) $/;" f -mimeheader_dump imaputil.c /^u64_t mimeheader_dump(MEM * outmem, struct dm_list * mimeheader)$/;" f +mime_readheader mime.c /^int mime_readheader(struct DbmailMessage *message, u64_t * msgbuf_idx, struct dm_list *mimelist, u64_t * headersize)$/;" f +mime_unwrap dm_imaputil.c /^int mime_unwrap(char *to, const char *from) $/;" f +mimeheader_dump dm_imaputil.c /^u64_t mimeheader_dump(MEM * outmem, struct dm_list * mimeheader)$/;" f mimelist main.c /^struct dm_list mimelist; \/* raw unformatted mimefields and values *\/$/;" v mkpassword dbmail-user.c /^int mkpassword(const char * const user, const char * const passwd,$/;" f month_desc dm_search.c /^const char *month_desc[] = {$/;" v -month_len imaputil.c /^const int month_len[] = {$/;" v +month_len dm_imaputil.c /^const int month_len[] = {$/;" v mopen memblock.c /^MEM *mopen()$/;" f mread memblock.c /^int mread(void *data, int size, MEM * m)$/;" f mreset memblock.c /^void mreset(MEM * m)$/;" f @@ -844,7 +858,8 @@ no_to_all dbmail-user.c /^int no_to_all = 0;$/;" v no_to_all maintenance.c /^int no_to_all = 0;$/;" v noop_child_sig_handler serverchild.c /^void noop_child_sig_handler(int sig, siginfo_t *info UNUSED, void *data UNUSED)$/;" f num_from_imapdate dm_search.c /^int num_from_imapdate(const char *date)$/;" f -perform_imap_search imaputil.c /^int perform_imap_search(unsigned int *rset, int setlen, search_key_t * sk,$/;" f +part_get_logical_part dm_imaputil.c /^static char * part_get_logical_part(const GMimeObject *object, const char * specifier) $/;" f file: +perform_imap_search dm_imaputil.c /^int perform_imap_search(unsigned int *rset, int setlen, search_key_t * sk,$/;" f pidFile imapd.c /^char *pidFile = DEFAULT_PID_DIR "dbmail-imapd" DEFAULT_PID_EXT;$/;" v pidFile lmtpd.c /^char *pidFile = DEFAULT_PID_DIR "dbmail-lmtpd" DEFAULT_PID_EXT;$/;" v pidFile pop3d.c /^char *pidFile = DEFAULT_PID_DIR "dbmail-pop3d" DEFAULT_PID_EXT;$/;" v @@ -860,8 +875,7 @@ pop3_handle_connection pop3.c /^int pop3_handle_connection(clientinfo_t * ci)$/; pop_before_smtp pop3d.c /^int pop_before_smtp = 0;$/;" v print_mimelist check_dbmail_imapd.c /^void print_mimelist(struct dm_list *mimelist)$/;" f process_exists pidfile.c /^static int process_exists(pid_t pid)$/;" f file: -qerrorf maintenance.c 61;" d file: -qprintf maintenance.c 55;" d file: +qerrorf maintenance.c 45;" d file: query db.c /^char query[DEF_QUERYSIZE]; $/;" v query dbmail-imapsession.c /^char query[DEF_QUERYSIZE];$/;" v query dbmail-message.c /^char query[DEF_QUERYSIZE];$/;" v @@ -875,16 +889,15 @@ quota_get_quota quota.c /^quota_t *quota_get_quota(u64_t useridnr, char *quotaro quota_get_quotaroot quota.c /^char *quota_get_quotaroot(u64_t useridnr, const char *mailbox,$/;" f quota_set_resource_limit quota.c /^void quota_set_resource_limit(quota_t * quota, int resource_idx,$/;" f quota_set_root quota.c /^int quota_set_root(quota_t * quota, char *root)$/;" f -quoted_string_out imaputil.c /^int quoted_string_out(FILE * outstream, const char *s)$/;" f -qverbosef maintenance.c 58;" d file: +quoted_string_out dm_imaputil.c /^int quoted_string_out(FILE * outstream, const char *s)$/;" f +qverbosef maintenance.c 42;" d file: rcpt lmtp.c /^static struct dm_list from, rcpt;$/;" v file: read_from_stream misc.c /^int read_from_stream(FILE * instream, char **m_buf, size_t maxlen)$/;" f read_script_file sievecmd.c /^int read_script_file(FILE * f, char **m_buf)$/;" f reallyquiet dbmail-user.c /^int reallyquiet = 0; \/* Don't print errors. *\/$/;" v reallyquiet maintenance.c /^int reallyquiet = 0;$/;" v returnpath main.c /^struct dm_list returnpath; \/* returnpath (should aways be just 1 hop) *\/$/;" v -rfcheader_dump imaputil.c /^u64_t rfcheader_dump(MEM * outmem, struct dm_list * rfcheader,$/;" f -rowlength dbmsgbuf.c /^static u64_t rowlength = 0; \/**< length of current row*\/$/;" v file: +rfcheader_dump dm_imaputil.c /^u64_t rfcheader_dump(MEM * outmem, struct dm_list * rfcheader,$/;" f rowpos dbmsgbuf.c /^static u64_t rowpos = 0; \/**< current position in row *\/$/;" v file: sb_lockfd pool.c /^static int sb_lockfd;$/;" v file: scoreboard pool.c /^static Scoreboard_t *scoreboard;$/;" v file: @@ -895,8 +908,8 @@ scoreboard_lock_new pool.c /^void scoreboard_lock_new(void)$/;" f scoreboard_new pool.c /^void scoreboard_new(serverConfig_t * conf)$/;" f scoreboard_release pool.c /^void scoreboard_release(pid_t pid)$/;" f scoreboard_setup pool.c /^void scoreboard_setup(void) { $/;" f -search_cost imaputil.c /^static const char *search_cost[] = { "b","b","c","c","c","b","d","d","d","c","e","e","b","b","j","j","j" };$/;" v file: -send_data imaputil.c /^void send_data(FILE * to, MEM * from, int cnt)$/;" f +search_cost dm_imaputil.c /^static const char *search_cost[] = { "b","b","c","c","c","b","d","d","d","c","e","e","b","b","j","j","j" };$/;" v file: +send_data dm_imaputil.c /^void send_data(FILE * to, MEM * from, int cnt)$/;" f send_notification pipe.c /^static int send_notification(const char *to, const char *from,$/;" f file: send_quota imapcommands.c /^void send_quota(struct ImapSession *self, quota_t * quota)$/;" f send_reply pipe.c /^static int send_reply(struct dm_list *headerfields, const char *body)$/;" f file: @@ -905,6 +918,7 @@ set_lock pool.c /^int set_lock(int type)$/;" f setup check_dbmail_common.c /^void setup(void)$/;" f setup check_dbmail_deliver.c /^void setup(void)$/;" f setup check_dbmail_imapd.c /^void setup(void)$/;" f +setup check_dbmail_mailbox.c /^void setup(void)$/;" f setup check_dbmail_message.c /^void setup(void)$/;" f setup check_dbmail_server.c /^void setup(void)$/;" f setup check_dbmail_user.c /^void setup(void)$/;" f @@ -913,14 +927,15 @@ shmid pool.c /^static int shmid;$/;" v file: sieve_extensions timsieved.c /^char *sieve_extensions = NULL;$/;" v socket_match misc.c /^static int socket_match(const char *base, const char *test)$/;" f file: sort_and_deliver dbmail-message.c /^dsn_class_t sort_and_deliver(struct DbmailMessage *message, u64_t useridnr, const char *mailbox)$/;" f -sort_search imaputil.c /^int sort_search(struct dm_list *searchlist) $/;" f +sort_search dm_imaputil.c /^int sort_search(struct dm_list *searchlist) $/;" f state_new pool.c /^State_t state_new(void)$/;" f store_message_in_blocks pipe.c /^int store_message_in_blocks(const char *message, u64_t message_size,$/;" f -stridx imaputil.c /^size_t stridx(const char *s, char ch)$/;" f +stridx dm_imaputil.c /^size_t stridx(const char *s, char ch)$/;" f strtomaxmail dbmail-user.c /^u64_t strtomaxmail(const char * const str)$/;" f teardown check_dbmail_common.c /^void teardown(void)$/;" f teardown check_dbmail_deliver.c /^void teardown(void)$/;" f teardown check_dbmail_imapd.c /^void teardown(void)$/;" f +teardown check_dbmail_mailbox.c /^void teardown(void)$/;" f teardown check_dbmail_message.c /^void teardown(void)$/;" f teardown check_dbmail_server.c /^void teardown(void)$/;" f teardown check_dbmail_user.c /^void teardown(void)$/;" f diff --git a/test-scripts/testimap.py b/test-scripts/testimap.py index 00835f68..a944627b 100755 --- a/test-scripts/testimap.py +++ b/test-scripts/testimap.py @@ -18,7 +18,9 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # $Id$ +# For a protocol trace set to 4 DEBUG = 0 +#DEBUG = 4 # select 'stream' for non-forking mode TYPE = 'stream' @@ -27,8 +29,9 @@ TYPE = 'stream' import unittest, imaplib, re -import sys, traceback, getopt +import sys, traceback, getopt, string from email.MIMEText import MIMEText +from email.MIMEMultipart import MIMEMultipart unimplementedError = 'Dbmail testcase unimplemented' @@ -50,9 +53,18 @@ def getMessageStrict(): m.add_header("To","testuser@foo.org") m.add_header("From","somewher@foo.org") m.add_header("Subject","dbmail test message") - return str(m) - + return m + +def getMultiPart(): + m=MIMEMultipart() + m.attach(getMessageStrict()) + m.add_header("To","testaddr@bar.org") + m.add_header("From","testuser@foo.org") + m.add_header("Subject","dbmail multipart message") + return m + TESTMSG['strict822']=getMessageStrict() +TESTMSG['multipart']=getMultiPart() def getsock(): if TYPE == 'network': @@ -60,6 +72,8 @@ def getsock(): elif TYPE == 'stream': return imaplib.IMAP4_stream(DAEMONBIN) +def strip_crlf(s): + return string.replace(s,'\r','') class testImapServer(unittest.TestCase): @@ -74,19 +88,27 @@ class testImapServer(unittest.TestCase): Append message to named mailbox. """ # check for OK - self.assertEquals(self.o.append('INBOX',(),"",TESTMSG['strict822'])[0],'OK') + self.assertEquals(self.o.append('INBOX',(),"",str(TESTMSG['strict822']))[0],'OK') # check for TRYCREATE - result=self.o.append('nosuchbox',(),"",TESTMSG['strict822']) + result=self.o.append('nosuchbox',(),"",str(TESTMSG['strict822'])) self.assertEquals(result[0],'NO') self.assertEquals(result[1][0][:11],'[TRYCREATE]') # test flags self.o.create('testappend') - self.o.append('testappend','\Flagged',"",TESTMSG['strict822']) + self.o.append('testappend','\Flagged',"",str(TESTMSG['strict822'])) self.o.select('testappend') id=self.o.recent()[1][0] - result = self.o.fetch(id,"(UID BODY.PEEK[])") + + result = self.o.fetch(id,"(UID BODY[])") self.assertEquals(result[0],'OK') - print result + + result = self.o.fetch(id,"(UID BODY[TEXT])") + self.assertEquals(result[0],'OK') + self.assertEquals(strip_crlf(result[1][0][1]),TESTMSG['strict822'].get_payload()) + + result = self.o.fetch(id,"(UID BODY.PEEK[TEXT])") + self.assertEquals(result[0],'OK') + self.assertEquals(strip_crlf(result[1][0][1]),TESTMSG['strict822'].get_payload()) # expect = ' FLAGS (\\Seen \\Flagged \\Recent))' # self.assertEquals(result,expect) @@ -115,7 +137,7 @@ class testImapServer(unittest.TestCase): """ self.o.create('testcopy1') self.o.create('testcopy2') - self.o.append('testcopy1',"","",TESTMSG['strict822']) + self.o.append('testcopy1',"","",str(TESTMSG['strict822'])) self.o.select('testcopy1') id = self.o.recent()[1][0] self.assertEquals(self.o.copy(id,'testcopy2'),('OK', ['COPY completed'])) @@ -155,30 +177,54 @@ class testImapServer(unittest.TestCase): BODY[TEXT])"'. Returned data are tuples of message part envelope and data. """ - self.o.append('INBOX','','',TESTMSG['strict822']) - self.o.select() - self.assertEquals(self.o.fetch("1:2","(Flags)")[0],'OK') + self.o.create('tmpbox') + self.o.append('tmpbox','','',str(TESTMSG['strict822'])) + self.o.select('tmpbox') + self.assertEquals(self.o.fetch("1:*","(Flags)")[0],'OK') id=self.o.recent()[1][0] + # fetch complete message. order and number of headers may differ result = self.o.fetch(id,"(UID BODY[])") self.assertEquals(result[0],'OK') + + # get the body. must equal input message's body + result = self.o.fetch(id,"(UID BODY[TEXT])") + print result + bodytext = strip_crlf(result[1][0][1]) + self.assertEquals(bodytext,TESTMSG['strict822'].get_payload()) + + result = self.o.fetch(id,"(UID BODYSTRUCTURE)") + self.assertEquals(result[0],'OK') print result + result = self.o.fetch(id,"(UID BODY[TEXT]<0.20>)") + #print result + self.assertEquals(result[0],'OK') self.assertEquals(self.o.fetch(id,"(UID BODY.PEEK[TEXT]<0.30>)")[0],'OK') self.assertEquals(self.o.fetch(id,"(UID RFC822.SIZE)")[0],'OK') result=self.o.fetch(id,"(UID RFC822.HEADER)") + + #print result + self.assertEquals(result[0],'OK') self.assertEquals(result[1][0][1][-2:],'\r\n') - result=self.o.fetch("1:2","(UID RFC822.HEADER)") + result=self.o.fetch(id,"(UID RFC822.HEADER)") self.assertEquals(result[0],'OK') + #print result - result=self.o.fetch("1","(BODY.PEEK[HEADER.FIELDS (References X-Ref X-Priority X-MSMail-Priority X-MSOESRec Newsgroups)] ENVELOPE RFC822.SIZE UID FLAGS INTERNALDATE)") + # OE query + result=self.o.fetch(id,"(BODY.PEEK[HEADER.FIELDS (References X-Ref X-Priority X-MSMail-Priority X-MSOESRec Newsgroups)] ENVELOPE RFC822.SIZE UID FLAGS INTERNALDATE)") self.assertEquals(result[0],'OK') + print result + # TB query + result=self.o.fetch(id,"(UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type)])") + print result + def testGetacl(self): """ `getacl(mailbox)' @@ -20,18 +20,7 @@ /* implementation for tims commands according to RFC 1081 */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "dbmail.h" -#include "sort/sortsieve.h" -#include "timsieve.h" -#include "db.h" -#include "debug.h" -#include "dbmailtypes.h" -#include "auth.h" -#include "misc.h" #include <sieve2_interface.h> @@ -26,32 +26,7 @@ Copyright (C) 2004 Aaron Stone aaron at serendipity dot cx #ifndef _TIMS_H #define _TIMS_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <sys/wait.h> -#include <signal.h> -#include <time.h> - -#include "misc.h" -#include "list.h" -#include "debug.h" #include "dbmail.h" -#include "dbmailtypes.h" /* processes */ diff --git a/timsieved.c b/timsieved.c index 89038d1c..527f2dd4 100644 --- a/timsieved.c +++ b/timsieved.c @@ -24,27 +24,7 @@ Copyright (C) 2004 Aaron Stone aaron at serendipity dot cx * main prg for tims daemon */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <signal.h> -#include <errno.h> -#include "imap4.h" -#include "server.h" -#include "debug.h" -#include "misc.h" -#include "pidfile.h" #include "dbmail.h" -#include "dbmailtypes.h" -#include "timsieve.h" -#include "sort/sortsieve.h" - #define PNAME "dbmail/timsieved" @@ -24,35 +24,12 @@ * * - moving most code to dbmail-users.c. Just a thin wrapper left */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <unistd.h> -#include <time.h> -#include <stdarg.h> -#include <sys/types.h> -#include <stdio.h> -#include <termios.h> -#include <stdlib.h> -#include <string.h> -#ifdef HAVE_CRYPT_H -#include <crypt.h> -#endif - -#include "dbmail-user.h" -#include "auth.h" #include "dbmail.h" -#include "list.h" -#include "debug.h" -#include "db.h" -#include "misc.h" -#include "dbmd5.h" char *configFile = DEFAULT_CONFIG_FILE; #define SHADOWFILE "/etc/shadow" -#define PNAME "dbmail/adduser" +#define PNAME "dbmail/user" extern db_param_t _db_params; |