Data publikacji: Oct 30, 2009 6:54:16 PM
Uwaga: rozwiązanie nie jest poprawne! PostfixAdmin oczekuje unikatowości na alias(address) - przy dwóch i więcej tych samych rekordach nie działa. Rozwiązaniem jest modyfikacja kolumny goto - dodanie stosowanego adresu po "," i ew. go usuwanie. W przyszłości może poprawię ten post.
Zaczynamy od dodania funkcji:
create or replace function set_vacation(_t_email text, _t_subject text, _t_body text) returns integer as $$
declare
_t_goto text;
begin
update vacation set subject = _t_subject, body = _t_body, active = true where email = _t_email;
if not found then
insert into vacation(email, domain, subject, body, active) values(_t_email, 'ALL', _t_subject, _t_body, TRUE);
_t_goto := replace(_t_email, '@', '#') || '@autoreply.vacation';
delete from alias where address = _t_email and goto = _t_goto;
insert into alias(address, domain, goto) values (_t_email, 'ALL', _t_goto);
end if;
return 1;
end;
$$ language 'plpgsql' security definer;
create or replace function unset_vacation(_t_email text) returns integer as $$
declare
_t_goto text;
begin
_t_goto := replace(_t_email, '@', '#') || '@autoreply.vacation';
delete from vacation where email = _t_email;
delete from alias where address = _t_email and goto = _t_goto;
return 1;
end;
$$ language 'plpgsql' security definer;
Nadziergałem coś podobnego dla mysql. Lecz musiałem zmodyfikowac moduł vacation do horde, aby pozwalał na kilka komend w polach z custom queries (BEGIN; costam ... COMMIT). Funkcję by tez można napisać, ale nie lubie mysql.
Trochę modyfikacji schematu:
alter table alias drop constraint "alias_key";
create index alias_address_key on alias(address);
Instalujemy http://www.horde.org/vacation/
Edytujemy vacation/lib/Driver/customsql.php, w funkcjach unsetVacation i setVacation usuwamy (komentujemy):
if ($this->_db->affectedRows() == 0) {
return PEAR::raiseError(_("The vacation notice cannot be set. Check the password."));
}
if ($result !== DB_OK) {
return PEAR::raiseError(_("An unknown error occured while enabling the vacation notice."));
}
W konfiguracji podajemy (z ważniejszych):
The driver to use: SQL driver with custom queries
Query to set vacation messages: SELECT set_vacation(\U, \S, \M)
Query to disable vacation messages: SELECT unset_vacation(\U)
Query to retrieve vacation status: SELECT active as vacation FROM vacation WHERE email = \U
Should we log the user automatically in with the username and password he uses to login to Horde?: Yes, with full username
Give the user the ability to change which aliases to use?: odznaczyć
Tworzymy użytkownika vacation w grupie vacation, shell /bin/false, home /var/spool/vacation.
Kopiujemy skrypt vacation.pl z postfixadmin do /var/spool/vacation/. Upewniamy się że należy do vacation:vacation i można go wykonać (MIME:EncWords, MIME:Charset).
Edytujemy, ustawiamy poprawne parametry połączenia do bazy danych.
Ustawiamy logowanie do pliku. Najlepiej katalog /var/log/vacation. Oczywiscie, którego właścicielem jest vacation:vacation.
Edytujemy /etc/postfix/master.cnf
vacation unix - n n - - pipe
flags=DRhu user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}
Edytujemy /etc/postfix/main.cnf
# jeżeli mamy już jakieś transport_maps, to dopisujemy hash:/ .... na początku
transport_maps = hash:/etc/postfix/transport_maps
vacation_destination_recipient_limit=1
Edytujemy /etc/postfix/transport_maps:
autoreply.vacation vacation:
Przebudowujemy mapy:
postmap /etc/postfix/transport_maps
I restart postfixa:
/etc/init.d/postfix reload
Powinno śmigać.
Jak coś nie działa to: patrz /var/log/mail.log, /var/log/vacation/vacation.log.
Uwaga: vacation.pl wysyła tylko raz wiadomość do każdego nadawcy. Więc należy odpowiednio kasować wpisy w vacation_notifications w czasie testów.