]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
email settings for post by email
authorEvan Prodromou <evan@prodromou.name>
Sat, 19 Jul 2008 20:26:25 +0000 (16:26 -0400)
committerEvan Prodromou <evan@prodromou.name>
Sat, 19 Jul 2008 20:26:25 +0000 (16:26 -0400)
darcs-hash:20080719202625-84dde-52b3d6710302f55e35ef57ea0aa4aff07cbeafaa.gz

actions/emailsettings.php
classes/User.php
classes/stoica.ini
db/laconica.sql
lib/mail.php
maildaemon.php

index b7e356c25683a6171298090ed729b91a17707a00..d8a7bb6c3372e473e4362dbfd394cf50fd05a355 100644 (file)
@@ -63,14 +63,36 @@ class EmailsettingsAction extends SettingsAction {
                        }
                }
 
+               if ($user->email) {
+                       common_element('h2', NULL, _('Incoming email'));
+                       
+                       if ($user->incomingemail) {
+                               common_element_start('p');
+                               common_element('span', 'address', $user->incomingemail);
+                               common_element('span', 'input_instructions',
+                                                          _('Send email to this address to post new notices.'));
+                               common_element_end('p');
+                               common_submit('removeincoming', _('Remove'));
+                       }
+                       
+                       common_element_start('p');
+                       common_element('span', 'input_instructions',
+                                                  _('Make a new email address for posting to; cancels the old one.'));
+                       common_element_end('p');
+                       common_submit('newincoming', _('New'));
+               }
+               
                common_element('h2', NULL, _('Preferences'));
-
-               common_checkbox('emailnotifysub',
-                               _('Send me notices of new subscriptions through email.'),
-                               $user->emailnotifysub);
                
+               common_checkbox('emailnotifysub',
+                                               _('Send me notices of new subscriptions through email.'),
+                                               $user->emailnotifysub);
+               common_checkbox('emailpost',
+                                               _('I want to post notices by email.'),
+                                               $user->emailpost);
+                       
                common_submit('save', _('Save'));
-
+               
                common_element_end('form');
                common_show_footer();
        }
@@ -97,6 +119,10 @@ class EmailsettingsAction extends SettingsAction {
                        $this->cancel_confirmation();
                } else if ($this->arg('remove')) {
                        $this->remove_address();
+               } else if ($this->arg('removeincoming')) {
+                       $this->remove_incoming();
+               } else if ($this->arg('newincoming')) {
+                       $this->new_incoming();
                } else {
                        $this->show_form(_('Unexpected form submission.'));
                }
@@ -228,11 +254,42 @@ class EmailsettingsAction extends SettingsAction {
                }
                $user->query('COMMIT');
 
-               # XXX: unsubscribe to the old address
-
                $this->show_form(_('The address was removed.'), TRUE);
        }
 
+       function remove_incoming() {
+               $user = common_current_user();
+               
+               if (!$user->incomingemail) {
+                       $this->show_form(_('No incoming email address.'));
+                       return;
+               }
+               
+               $orig = clone($user);
+               $user->incomingemail = NULL;
+               
+               if (!$user->update($orig)) {
+                       common_log_db_error($user, 'UPDATE', __FILE__);
+                       $this->server_error(_("Couldn't update user record."));
+               }
+               
+               $this->show_form(_('Incoming email address removed.'), TRUE);
+       }
+
+       function new_incoming() {
+               $user = common_current_user();
+               
+               $orig = clone($user);
+               $user->incomingemail = mail_new_incoming_address();
+               
+               if (!$user->update($orig)) {
+                       common_log_db_error($user, 'UPDATE', __FILE__);
+                       $this->server_error(_("Couldn't update user record."));
+               }
+
+               $this->show_form(_('New incoming email address added.'), TRUE);
+       }
+       
        function email_exists($email) {
                $user = common_current_user();
                $other = User::staticGet('email', $email);
index 8600bae7a2370e43c9cb61958abea79cfa211862..0292b558236e922f1d269e9bbe8ebf39269d2afa 100644 (file)
@@ -36,6 +36,7 @@ class User extends DB_DataObject
     public $email;                           // varchar(255)  unique_key
     public $incomingemail;                   // varchar(255)  unique_key
     public $emailnotifysub;                  // tinyint(1)   default_1
+    public $emailpost;                       // tinyint(1)   default_1
     public $jabber;                          // varchar(255)  unique_key
     public $jabbernotify;                    // tinyint(1)  
     public $jabberreplies;                   // tinyint(1)  
index 6ee2981c2a3d7f7b620a5e4f987ca853ab1d1203..c79e095dce88928bad4ccc3957e4524386d542ac 100644 (file)
@@ -160,6 +160,7 @@ password = 2
 email = 2
 incomingemail = 2
 emailnotifysub = 17
+emailpost = 17
 jabber = 2
 jabbernotify = 17
 jabberreplies = 17
index 4591caf1418f4450590c524e2a1706df8d018aca..a598e447094c72c2bb3699bf65eb5dde750317ef 100644 (file)
@@ -47,6 +47,7 @@ create table user (
     email varchar(255) unique key comment 'email address for password recovery etc.',
     incomingemail varchar(255) unique key comment 'email address for post-by-email',
     emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
+    emailpost tinyint default 1 comment 'Post by email',
     jabber varchar(255) unique key comment 'jabber ID for notices',
     jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
     jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
index f852f385a3d3a357dad22440b1c74fa7af2fbabe..21a1c7a8f25dc8836e083df9a699b801d139c2df 100644 (file)
@@ -48,13 +48,21 @@ function mail_send($recipients, $headers, $body) {
        return true;
 }
 
+function mail_domain() {
+       $maildomain = common_config('mail', 'domain');
+       if (!$maildomain) {
+               $maildomain = common_config('site', 'server');
+       }
+       return $maildomain;
+}
+
 function mail_notify_from() {
-       global $config;
-       if ($config['mail']['notifyfrom']) {
-               return $config['mail']['notifyfrom'];
-       } else {
-               return $config['site']['name'] . ' <noreply@'.$config['site']['server'].'>';
+       $notifyfrom = common_config('mail', 'notifyfrom');
+       if (!$notifyfrom) {
+               $domain = mail_domain();
+               $notifyfrom = common_config('site', 'name') .' <noreply@'.$domain.'>';
        }
+       return $notifyfrom;
 }
 
 function mail_to_user(&$user, $subject, $body, $address=NULL) {
@@ -121,3 +129,31 @@ function mail_subscribe_notify($listenee, $listener) {
                mail_send($recipients, $headers, $body);
        }
 }
+
+function mail_new_incoming_notify($user) {
+
+       $profile = $user->getProfile();
+       $name = $profile->getBestName();
+       
+       $headers['From'] = $user->incomingemail;
+       $headers['To'] = $name . ' <' . $user->email . '>';
+       $headers['Subject'] = sprintf(_('New email address for posting to %s'),
+                                                                 common_config('site', 'name'));
+       
+       $body  = sprintf(_("You have a new posting address on %1\$s.\n\n".
+                                          "Send email to %2\$s to post new messages.\n\n".
+                                          "More email instructions at %3\$s.\n\n".
+                                          "Faithfully yours,\n%4\$s"),
+                                        common_config('site', 'name'),
+                                        $user->incomingemail,
+                                        common_local_url('doc', array('title' => 'email')),
+                                        common_config('site', 'name'));
+       
+       mail_send($user->email, $headers, $body);
+}
+
+function mail_new_incoming_address() {
+       $prefix = common_good_rand(8);
+       $suffix = mail_domain();
+       return $prefix . '@' . $suffix;
+}
index ba88774bf33520a4712b66d56721efe0714963f0..59659b9909c1075c277843b026dd82eae012d194 100755 (executable)
@@ -50,6 +50,8 @@ class MailerDaemon {
                if (!$this->user_match_to($user, $to)) {
                        $this->error($from, _('Sorry, that is not your incoming email address.'));
                }
+               if (!$user->emailpost) {
+               }
                $response = $this->handle_command($user, $msg);
                if ($response) {
                        $this->respond($from, $to, $response);