diff options
author | Evan Prodromou <evan@prodromou.name> | 2008-07-19 16:26:25 -0400 |
---|---|---|
committer | Evan Prodromou <evan@prodromou.name> | 2008-07-19 16:26:25 -0400 |
commit | 594811350c67feede35d50f05a9e1311b8c4c036 (patch) | |
tree | f97ad0af92be3533ce38428d93129ca1b8869450 | |
parent | 1d7450ca16cc210ea0ed4a7f68f2e6bff83b00fa (diff) |
email settings for post by email
darcs-hash:20080719202625-84dde-52b3d6710302f55e35ef57ea0aa4aff07cbeafaa.gz
-rw-r--r-- | actions/emailsettings.php | 71 | ||||
-rw-r--r-- | classes/User.php | 1 | ||||
-rw-r--r-- | classes/stoica.ini | 1 | ||||
-rw-r--r-- | db/laconica.sql | 1 | ||||
-rw-r--r-- | lib/mail.php | 46 | ||||
-rwxr-xr-x | maildaemon.php | 2 |
6 files changed, 110 insertions, 12 deletions
diff --git a/actions/emailsettings.php b/actions/emailsettings.php index b7e356c25..d8a7bb6c3 100644 --- a/actions/emailsettings.php +++ b/actions/emailsettings.php @@ -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); diff --git a/classes/User.php b/classes/User.php index 8600bae7a..0292b5582 100644 --- a/classes/User.php +++ b/classes/User.php @@ -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) diff --git a/classes/stoica.ini b/classes/stoica.ini index 6ee2981c2..c79e095dc 100644 --- a/classes/stoica.ini +++ b/classes/stoica.ini @@ -160,6 +160,7 @@ password = 2 email = 2 incomingemail = 2 emailnotifysub = 17 +emailpost = 17 jabber = 2 jabbernotify = 17 jabberreplies = 17 diff --git a/db/laconica.sql b/db/laconica.sql index 4591caf14..a598e4470 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -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', diff --git a/lib/mail.php b/lib/mail.php index f852f385a..21a1c7a8f 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -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; +} diff --git a/maildaemon.php b/maildaemon.php index ba88774bf..59659b990 100755 --- a/maildaemon.php +++ b/maildaemon.php @@ -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); |