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

vacation activation/end date support #26

Open nerijus opened 9 years ago

nerijus commented 9 years ago

postfixadmin-2.91 supports "ability to choose activation date, end date and reply interval for vacation message". Does rc-vacation plugin support it?

wpoely86 commented 9 years ago

@nerijus Have you looked at contrib/postfix-schema.sql ?

nerijus commented 9 years ago

I've looked now and made a diff against the latest pfadmin schema:

--- postfix-schema.sql  2014-10-02 13:19:11.476977392 +0300
+++ vacation.sql    2014-10-02 13:18:54.478977096 +0300
@@ -1,11 +1,13 @@
 CREATE TABLE IF NOT EXISTS `vacation` (
   `email` varchar(255) NOT NULL,
   `subject` varchar(255) CHARACTER SET utf8 NOT NULL,
   `body` text CHARACTER SET utf8 NOT NULL,
+  `activefrom` timestamp NOT NULL DEFAULT '1999-12-31 22:00:00',
+  `activeuntil` timestamp NOT NULL DEFAULT '1999-12-31 22:00:00',
   `cache` text NOT NULL,
   `domain` varchar(255) NOT NULL,
+  `interval_time` int(11) NOT NULL DEFAULT '0',
   `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
-  `active` tinyint(1) NOT NULL DEFAULT '1',
-  PRIMARY KEY (`email`),
-  KEY `email` (`email`)
+  `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  `active` tinyint(1) NOT NULL DEFAULT '1'
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation';

Is it possible to add support for modifying activefrom and activeuntil?

nightah commented 8 years ago

The values are generated in php as Unix time, however Postfix requires them in 'YYYY-MM-DD HH:MM:SS' format.

Below the write query is converted to the required format for Postfix to store and action. The read query needs to be converted back to Unix time so when you are interacting with the jquery calendar you get the stored time (if it exists) as opposed to a time of '01-01-1970' in the widget.

Change the following sections in your config.inc.php:

// read data queries $rcmail_config['vacation_sql_read'] = // MySQL array( "SELECT subject AS vacation_subject, body AS vacation_message, active AS vacation_enable, UNIX_TIMESTAMP(activefrom) AS vacation_start, UNIX_TIMESTAMP(activeuntil) AS vacation_end FROM vacation WHERE email=%username AND domain=%email_domain;" );

// write data queries $rcmail_config['vacation_sql_write'] = // MySQL array( "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", "INSERT INTO vacation (email,domain,subject,body,created,active,activefrom,activeuntil) VALUES (%email,%email_domain,%vacation_subject,%vacation_message,NOW(),%vacation_enable,FROM_UNIXTIME(%vacation_start, '%Y-%m-%d 00:00:00'),FROM_UNIXTIME(%vacation_end, '%Y-%m-%d 23:59:59'));",

nerijus commented 3 years ago

Thank you, it worked after I added 'cache' field which is a leftover from 2.2 (see https://sourceforge.net/p/postfixadmin/bugs/345/). The diff looks like this:

-                       activefrom AS vacation_start,
-                       activeuntil AS vacation_end
+                       UNIX_TIMESTAMP(activefrom) AS vacation_start,
+                       UNIX_TIMESTAMP(activeuntil) AS vacation_end

                        "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;",
-                       "INSERT INTO vacation (email,domain,subject,body,created,active,activefrom,activeuntil)
-                               VALUES (%email,%email_domain,%vacation_subject,%vacation_message,NOW(),%vacation_enable,%vacation_start,%vacation_end);",
+                       "INSERT INTO vacation (email,domain,subject,body,created,active,activefrom,activeuntil,cache)
+                               VALUES (%email,%email_domain,%vacation_subject,%vacation_message,NOW(),%vacation_enable,FROM_UNIXTIME(%vacation_start, '%Y-%m-%d 00:00:00'),FROM_UNIXTIME(%vacation_end, '%Y-%m-%d 23:59:59'),'');",

                        "DELETE from vacation_notification WHERE on_vacation=%email;",