}
}
+ 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();
}
$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.'));
}
}
$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);
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)
email = 2
incomingemail = 2
emailnotifysub = 17
+emailpost = 17
jabber = 2
jabbernotify = 17
jabberreplies = 17
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',
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) {
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;
+}
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);