Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to avoid losing alias #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

to avoid losing alias #17

wants to merge 3 commits into from

Conversation

lluis
Copy link

@lluis lluis commented Apr 2, 2013

Activating and deactivating vacation was deleting custom aliases

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

@superlgn
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants