diff --git a/.gitattributes b/.gitattributes index 5c095e3c..62e9d0e1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -610,6 +610,7 @@ src/functions.sh -text src/functions_dns.sh -text src/functions_hosting.sh -text src/inotify_update_domains.sh -text +src/mail_dodelete.php -text src/mem_add -text src/mem_del -text src/popimap-log-login.sh -text diff --git a/bureau/class/m_mail.php b/bureau/class/m_mail.php index 56eb8061..cc4333b6 100644 --- a/bureau/class/m_mail.php +++ b/bureau/class/m_mail.php @@ -405,6 +405,16 @@ ORDER BY return true; } + // return the alternc account's ID of the mail_id + function get_account_by_mail_id($mail_id) { + global $db,$err; + $db->query("select compte as uid from domaines d, address a where a.domain_id = d.id and a.id = $mail_id"); + if ( !$db->next_record()) { + return false; + } + return $db->f('uid'); + } + /* ----------------------------------------------------------------- */ /** Function used to delete a mail from the db @@ -429,6 +439,9 @@ ORDER BY return false; } + $mailinfos=$this->get_details($mail_id); + $hooks->invoke('hook_mail_delete', array($mail_id, $mailinfos['address'].'@'.$mailinfos['domain'] )); + // Search for that address: $db->query("SELECT a.id, a.type, a.mail_action, m.mail_action AS mailbox_action, NOT ISNULL(m.id) AS islocal FROM address a LEFT JOIN mailbox m ON m.address_id=a.id WHERE a.id='$mail_id';"); if (!$db->next_record()) { diff --git a/roundcube/class/m_roundcube.php b/roundcube/class/m_roundcube.php index 53b86b50..8b1e9007 100644 --- a/roundcube/class/m_roundcube.php +++ b/roundcube/class/m_roundcube.php @@ -65,6 +65,22 @@ class m_roundcube { } + + /* ----------------------------------------------------------------- */ + /** Hook called when an email is REALLY deleted (by the cron, not just in the panel) + * @param mail_id integer the ID of the mail in the AlternC database + * @param fullmail string the deleted mail himself in the form of john@domain.tld + * @return boolean + */ + function hook_mail_delete_for_real($mail_id, $fullmail) { + // FIXME do something ! + // Include Roundcube configuration + // Delete from the roundcube configuration + // Use cleandb.sh filled by roundcube ? + printvar($mail_id); + printvar($fullmail); + } + } /* Class Roundcube */ diff --git a/src/Makefile b/src/Makefile index 7bb95925..ee40769c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------- # Purpose of file: Makefile des binaires de /usr/lib/alternc # ---------------------------------------------------------------------- -SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh courier-dovecot-migrate.pl popimap-log-login.sh mem_add mem_del quota_edit quota_get du.pl update_quota_mail.sh inotify_update_domains.sh functions.sh functions_hosting.sh functions_dns.sh +SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh courier-dovecot-migrate.pl popimap-log-login.sh mem_add mem_del quota_edit quota_get du.pl update_quota_mail.sh inotify_update_domains.sh functions.sh functions_hosting.sh functions_dns.sh mail_dodelete.php BIN=$(DESTDIR)/usr/lib/alternc/ install: diff --git a/src/mail_dodelete.php b/src/mail_dodelete.php new file mode 100644 index 00000000..a2fc3234 --- /dev/null +++ b/src/mail_dodelete.php @@ -0,0 +1,27 @@ +#!/usr/bin/php -q +get_account_by_mail_id($mail_id); + +// Ok, so be it +$mem->su($uid); + +// Get the mails informations +$mailinfos=$mail->get_details($mail_id); +// AND CALL THE HOOKS +$hooks->invoke('hook_mail_delete_for_real', array($mail_id, $mailinfos['address'].'@'.$mailinfos['domain'] )); + +// Bye bye + +echo "\n\n"; + +?> diff --git a/src/update_mails.sh b/src/update_mails.sh index 657ce989..1e41918f 100755 --- a/src/update_mails.sh +++ b/src/update_mails.sh @@ -43,6 +43,7 @@ echo $$ > "$LOCK_FILE" # If process is interrupted, the row isn't deleted. We have to force it by reseting mail_action to 'DELETE' mysql_query "SELECT id, quote(replace(path,'!','\\!')) FROM mailbox WHERE mail_action='DELETE';"|while read id path ; do mysql_query "UPDATE mailbox set mail_action='DELETING' WHERE id=$id;" + /usr/lib/alternc/mail_dodelete.php "$id" # Check there is no instruction of changing directory, and check the first part of the string if [[ "$path" =~ '../' || "$path" =~ '/..' || ! "'$ALTERNC_MAIL_LOC" == "${path:0:$((${#ALTERNC_MAIL_LOC}+1))}" ]] ; then # The path will be empty for mailman addresses