bhuisgen / rc-vacation

Vacation plugin for RoundCube Webmail
http://blog.hbis.fr/softwares/rc-vacation/
GNU General Public License v2.0
33 stars 37 forks source link

to avoid losing alias #17

Open lluis opened 11 years ago

lluis commented 11 years ago

Activating and deactivating vacation was deleting custom aliases

I checked #10 and #3 but none of it's code works for me

superlgn commented 11 years ago

Hi,

I recently downloaded the vacation plugin and went through some of this myself. I see the changes that you made to the config and it's similar to what I have now, but I had problems with forwards changing the order of the list and needed to run 3 update queries, similar to what the postfixadmin authors did to keep everything clean:

(from postfixadmin/edit-vacation.php) $goto= preg_replace ( "/$vacation_goto,/", '', $goto); $goto= preg_replace ( "/,$vacation_goto/", '', $goto); $goto= preg_replace ( "/$vacation_goto/", '', $goto);

I thought the 3 individual REPLACE(goto, CONCAT()) queries weren't very good so I searched around a bit and found a nice solution from Nicola De Franceschi on the mysql string functions page http://dev.mysql.com/doc/refman/5.0/en/string-functions.html specifically for managing comma delimited lists:

UPDATE temp SET string = TRIM(BOTH ',' FROM REPLACE(CONCAT("," , string, ","), CONCAT(",",'value_to_remove', ",") , ',')) WHERE id=1

I also added a modified=NOW() to the update statements so my vacation_sql_write variable looks like this:

// write data queries $rcmail_config['vacation_sql_write'] = array("DELETE FROM vacation WHERE email=%email AND " . "domain=%email_domain;", "DELETE from vacation_notification WHERE on_vacation=%email;", "INSERT INTO vacation (email,domain,subject,body,created," . "active) VALUES (%email,%email_domain,%vacation_subject," . "%vacation_message,NOW(),%vacation_enable);", "UPDATE alias SET goto=TRIM(BOTH ',' FROM REPLACE(CONCAT(',',goto,','),CONCAT(',',CONCAT(%email_local,'#',%email_domain,'@','autoreply.my.domain'),','),',')), modified=NOW() WHERE address=%email AND domain=%email_domain;", "UPDATE alias SET goto=CONCAT(goto,',',%email_local,'#',%email_domain,'@','autoreply.my.domain'), modified=NOW() WHERE address=%email AND domain=%email_domain AND %vacation_enable=1;" );

It's been working good so far with every combination of edits to vacation and forwarding I've tried. I'm not sure how compatible this is with other versions or databases, I only tested it on MySQL 5.1.

Thanks,

Mike