I encountered a problem with the code when trying to split the
authentication and message store databases. Some of the functions used the
wrong database hook, as for the developers the tables all sit in one table.

The patch below seemed to address it for me, but I'd also made a patch which
auto-created an inbox for a user when a new mail message was received --
which is also inline. It's only in mysql, as I don't know the postgres
hooks.

It's from the CVS about 3 weeks ago, but I still hope it's useful. I'd
really appreciate it if the database fixup could be applied to the CVS as
it's preventing me upgrading my local version :-)

/Mark 

  

diff -r -u dbmail.unmodified/db.h dbmail.mine/db.h
--- dbmail.unmodified/db.h      Wed Jun 12 03:43:43 2002
+++ dbmail.mine/db.h    Fri Jul 12 19:58:49 2002
@@ -15,6 +15,7 @@
 #include "memblock.h"
 
 #define DEF_QUERYSIZE 1024
+#define AUTH_QUERY_SIZE 1024
 #define DUMP_BUF_SIZE 1024
 
 #define ICHECK_RESULTSETSIZE 1000000
@@ -101,6 +102,7 @@
 int db_connect();
 int db_disconnect();
 int db_query (const char *thequery);
+int __auth_query (const char *thequery);
 
 char *db_get_config_item (char *item, int type);
 int db_clear_config();



diff -r -u dbmail.unmodified/maintenance.c dbmail.mine/maintenance.c
--- dbmail.unmodified/maintenance.c     Wed Jun 12 03:43:43 2002
+++ dbmail.mine/maintenance.c   Fri Jul 12 20:00:58 2002
@@ -117,9 +117,19 @@
       return 0;
     }
 
-  printf ("Opening connection to the database... ");
+  printf ("Opening connection to the user database... ");
 
   if (db_connect()==-1)
+    {
+      printf ("Failed. An error occured. Please check log.\n");
+      return -1;
+    }
+
+  printf ("Ok. Connected\n");
+
+  printf ("Opening connection to the message database... ");
+
+  if (auth_connect()==-1)
     {
       printf ("Failed. An error occured. Please check log.\n");
       return -1;



diff -r -u dbmail.unmodified/mbox2dbmail.c dbmail.mine/mbox2dbmail.c
--- dbmail.unmodified/mbox2dbmail.c     Tue May 28 23:18:12 2002
+++ dbmail.mine/mbox2dbmail.c   Sat Jul 27 16:22:30 2002
@@ -15,7 +15,8 @@
 #define MAX_LINESIZE 1024
 #define SMTP_INJECTOR "./dbmail-smtp -u "
 
-const char *mbox_delimiter_pattern = "^From [EMAIL PROTECTED]  ";
+//const char *mbox_delimiter_pattern = "^From [EMAIL PROTECTED]  ";
+const char *mbox_delimiter_pattern = "^From .*";
 
 int main(int argc, char *argv[])
 {



diff -r -u dbmail.unmodified/mysql/dbauthmysql.c
dbmail.mine/mysql/dbauthmysql.c
--- dbmail.unmodified/mysql/dbauthmysql.c       Wed Jun  5 04:04:53 2002
+++ dbmail.mine/mysql/dbauthmysql.c     Fri Jul 12 19:58:40 2002
@@ -18,13 +18,13 @@
 #include "../config.h"
 #include <time.h>
 
-#define AUTH_QUERY_SIZE 1024
-
 /* 
  * var's for dbase connection/query
  */
 char __auth_query_data[AUTH_QUERY_SIZE];
 MYSQL __auth_conn;
+extern MYSQL conn;
+extern char *query;
 MYSQL_RES *__auth_res;
 MYSQL_ROW __auth_row;
 
@@ -511,13 +511,13 @@
   useridnr = mysql_insert_id(&__auth_conn);
 
   /* creating query for adding mailbox */
-  snprintf (__auth_query_data, AUTH_QUERY_SIZE,"INSERT INTO mailboxes
(owner_idnr, name) VALUES (%llu,'INBOX')",
+  snprintf (query, AUTH_QUERY_SIZE,"INSERT INTO mailboxes (owner_idnr,
name) VALUES (%llu,'INBOX')",
           useridnr);
 
   trace (TRACE_DEBUG,"auth_adduser(): executing query for mailbox");
 
 
-  if (__auth_query(__auth_query_data))
+  if (db_query(query))
     {
       trace (TRACE_ERROR,"auth_adduser(): query failed for adding
mailbox");
       return -1;



diff -r -u dbmail.unmodified/mysql/dbmysql.c dbmail.mine/mysql/dbmysql.c
--- dbmail.unmodified/mysql/dbmysql.c   Wed Jul 10 20:00:59 2002
+++ dbmail.mine/mysql/dbmysql.c Sat Jul 27 14:41:04 2002
@@ -20,6 +20,8 @@
 #include "../auth.h"
 
 
+extern char __auth_query_data[AUTH_QUERY_SIZE];
+extern MYSQL __auth_conn;
 MYSQL conn;  
 MYSQL_RES *res;
 MYSQL_RES *checkres;
@@ -450,10 +452,38 @@
 
   if (mysql_num_rows(res)<1)
     {
-      trace (TRACE_DEBUG,"db_get_mailboxid(): user has no mailbox named
[%s]", mailbox);
+      trace(TRACE_ERROR,"db_get_mailboxid(): user has no mailbox named [%s]
- Creating", mailbox);
       mysql_free_result(res);
+ 
+         // create mailbox
+         db_createmailbox(mailbox, useridnr);
+
+       snprintf (query, DEF_QUERYSIZE,"SELECT mailbox_idnr FROM mailboxes
WHERE "
+                   "name=\'%s\' AND owner_idnr=%llu",
+                  mailbox, useridnr);
+
+         // double check to see if mailbox exists now
+         if (db_query(query)==-1)
+            {
+              trace(TRACE_ERROR, "db_get_mailboxid(): query failed");
+              return 0;
+            }
+
+        if ((res = mysql_store_result(&conn)) == NULL)
+           {
+             trace(TRACE_ERROR,"db_get_mailboxid(): mysql_store_result
failed: %s",mysql_error(&conn));
+             return 0;
+           }
+
+        if (mysql_num_rows(res)<1)
+           {
+             trace (TRACE_DEBUG,"db_get_mailboxid(): user has no mailbox
named [%s]. Couldn't create.", mailbox);
+             mysql_free_result(res);
+
+             return 0;
+           }
       
-      return 0; 
+         // if still here, the mailbox should have been created
     } 
 
   if ((row = mysql_fetch_row(res))==NULL)
@@ -1949,21 +1979,21 @@
       
       for (j=0; j<ncurr; j++)
        {
-         snprintf(query, DEF_QUERYSIZE, "SELECT user_idnr FROM users WHERE
user_idnr = %llu",
+         snprintf(__auth_query_data, DEF_QUERYSIZE, "SELECT user_idnr FROM
users WHERE user_idnr = %llu",
                   currids[j].userid);
  
-         if (db_query(query)==-1)
+         if (__auth_query(__auth_query_data)==-1)
            {
              list_freelist(&lostlist->start);
              my_free(currids);
              currids = NULL;
-             trace (TRACE_ERROR,"db_icheck_mailboxes(): Could not execute
query [%s]",query);
+             trace (TRACE_ERROR,"db_icheck_mailboxes(): Could not execute
query [%s]",__auth_query_data);
              return -1;
            }
          
-         if ((res = mysql_store_result(&conn)) == NULL)
+         if ((res = mysql_store_result(&__auth_conn)) == NULL)
            {
-             trace (TRACE_ERROR,"db_icheck_mailboxes(): mysql_store_result
failed:  %s",mysql_error(&conn));
+             trace (TRACE_ERROR,"db_icheck_mailboxes(): mysql_store_result
failed:  %s",mysql_error(&__auth_conn));
              return -1;
            }
 

diff -r -u dbmail.unmodified/sql/mysql/create_tables.mysql
dbmail.mine/sql/mysql/create_tables.mysql
--- dbmail.unmodified/sql/mysql/create_tables.mysql     Sat Jul 13 06:42:27
2002
+++ dbmail.mine/sql/mysql/create_tables.mysql   Fri May 31 05:11:35 2002
@@ -1,7 +1,8 @@
 # $Id: create_tables.mysql,v 1.11 2002/05/30 17:11:35 roel Exp $
 
-CREATE DATABASE dbmail_auth;
-USE dbmail_auth;
+CREATE DATABASE dbmail;
+
+USE dbmail;
 
 CREATE TABLE aliases (
    alias_idnr bigint(21) DEFAULT '0' NOT NULL auto_increment,
@@ -26,9 +27,6 @@
    UNIQUE useridnr_2 (user_idnr, userid),
    UNIQUE userid_2 (userid)
 );
-
-CREATE DATABASE dbmail_store;
-USE dbmail_store;
 
 CREATE TABLE mailboxes (
    mailbox_idnr bigint(21) DEFAULT '0' NOT NULL auto_increment,


Reply via email to