email settings for post by email
darcs-hash:20080719202625-84dde-52b3d6710302f55e35ef57ea0aa4aff07cbeafaa.gz
This commit is contained in:
parent
1d7450ca16
commit
594811350c
|
@ -63,14 +63,36 @@ class EmailsettingsAction extends SettingsAction {
|
|||
}
|
||||
}
|
||||
|
||||
common_element('h2', NULL, _('Preferences'));
|
||||
|
||||
common_checkbox('emailnotifysub',
|
||||
_('Send me notices of new subscriptions through email.'),
|
||||
$user->emailnotifysub);
|
||||
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('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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -160,6 +160,7 @@ password = 2
|
|||
email = 2
|
||||
incomingemail = 2
|
||||
emailnotifysub = 17
|
||||
emailpost = 17
|
||||
jabber = 2
|
||||
jabbernotify = 17
|
||||
jabberreplies = 17
|
||||
|
|
|
@ -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',
|
||||
|
|
48
lib/mail.php
48
lib/mail.php
|
@ -48,13 +48,21 @@ function mail_send($recipients, $headers, $body) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function mail_notify_from() {
|
||||
global $config;
|
||||
if ($config['mail']['notifyfrom']) {
|
||||
return $config['mail']['notifyfrom'];
|
||||
} else {
|
||||
return $config['site']['name'] . ' <noreply@'.$config['site']['server'].'>';
|
||||
function mail_domain() {
|
||||
$maildomain = common_config('mail', 'domain');
|
||||
if (!$maildomain) {
|
||||
$maildomain = common_config('site', 'server');
|
||||
}
|
||||
return $maildomain;
|
||||
}
|
||||
|
||||
function mail_notify_from() {
|
||||
$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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user