]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/maildaemon.php
Ticket 753
[quix0rs-gnu-social.git] / scripts / maildaemon.php
index 3d3b3095140444294be1ba67efbee74c637f1865..64f913bf924923f184d87ab03726be198deb5be9 100755 (executable)
@@ -42,7 +42,7 @@ class MailerDaemon {
        function handle_message($fname='php://stdin') {
                list($from, $to, $msg) = $this->parse_message($fname);
                if (!$from || !$to || !$msg) {
-                       $this->error(NULL, _t('Could not parse message.'));
+                       $this->error(NULL, _('Could not parse message.'));
                }
                common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20));
                $user = $this->user_from($from);
@@ -58,9 +58,8 @@ class MailerDaemon {
                        $this->error($from, _('Sorry, no incoming email allowed.'));
                        return false;
                }
-               $response = $this->handle_command($user, $msg);
+               $response = $this->handle_command($user, $from, $msg);
                if ($response) {
-                       $this->respond($from, $to, $response);
                        return true;
                }
                $msg = $this->cleanup_msg($msg);
@@ -97,31 +96,16 @@ class MailerDaemon {
                return false;
        }
 
-       function handle_command($user, $msg) {
-               $cmd = trim(strtolower($msg));
-               switch ($cmd) {
-                case 'off':
-                       $this->set_notify($user, false);
+       function handle_command($user, $from, $msg) {
+               $inter = new CommandInterpreter();
+               $cmd = $inter->handle_command($user, $msg);
+               if ($cmd) {
+                       $cmd->execute(new MailChannel($from));
                        return true;
-                case 'on':
-                       $this->set_notify($user, true);
-                       return true;
-                default:
-                       return false;
                }
+               return false;
        }
 
-       function set_notify($user, $value) {
-               $orig = clone($user);
-               $user->smsnotify = $value;
-               $result = $user->update($orig);
-               if (!$result) {
-                       common_log_db_error($user, 'UPDATE', __FILE__);
-                       return false;
-               }
-               return true;
-       }
-       
        function respond($from, $to, $response) {
 
                $headers['From'] = $to;