Daniel Mejia wrote: > Hi all, > > I have a VERY HUGE problem.. I have accidentally deleted a user with the > command > > # dbmail-users -d x...@xxx.xxx > > Is there any way to restore the user back with all his emails? Please help, > I am in big trouble if this is an irreversible action!
Oops. dbmail-users -d username basically doesn't do anything but DELETE FROM dbmail_users where userid='username', but because of the ways the tables are setup, this will trigger several cascades. The main ones that will interest you are: dbmail_users -> dbmail_mailboxes -> dbmail_messages. Until you run dbmail-util, the actual messages will still be there: in dbmail_physmessages and dbmail_messageblks. So do *not* run dbmail-util until you resolve this. And backup you data! It should be possible to reconnect all unconnected physmessages to a new messages and reconnect those to a new mailbox. create a new user that will contain the rescued messages. - insert into dbmail_users (userid,passwd) values ('newusername','password'); find the user_idnr: - select user_idnr from dbmail_users where userid='newusername'; this will give you $newuser_idnr create a mailbox for this user: - insert into dbmail_mailboxes (owner_idnr, name, seen_flag, answered_flag, deleted_flag, flagged_flag, recent_flag, draft_flag) values ($newuser_idnr, 'INBOX', 1,1,1,1,1,1); find the mailbox_idnr for this mailbox: - select mailbox_idnr from dbmail_mailboxes where owner_idnr=$newuser_idnr and name='INBOX'; this will give you $newuser_inbox_idnr; Ok, now the real work: find all unconnected physmessages that may have belonged to the deleted user. - select id from dbmail_physmessage p left join dbmail_messages m on p.id=m.physmessage_id where m.physmessage_id is null; - for each physmessage.id found thus create a new message: - insert into dbmail_messages (mailbox_idnr, physmessage_id) values ($newuser_inbox_idnr, $physmessage_id) After this you should be able to login to dbmail-imap with the newuser's id and password and see the messages. But like I said, this will *only* work if you haven't run dbmail-util since the accidental deletion. > > Thanx a million to all for your help!! > > Sincerely, > Daniel -- ________________________________________________________________ Paul Stevens paul at nfg.nl NET FACILITIES GROUP GPG/PGP: 1024D/11F8CD31 The Netherlands________________________________http://www.nfg.nl _______________________________________________ DBmail mailing list DBmail@dbmail.org http://mailman.fastxs.nl/cgi-bin/mailman/listinfo/dbmail