]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/mail.php
91eafa97ee28cf16dd6450cdfcae34e392e98a71
[quix0rs-gnu-social.git] / lib / mail.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once('Mail.php');
23
24 function mail_backend() {
25         static $backend = NULL;
26
27         if (!$backend) {
28                 global $config;
29                 $backend = Mail::factory($config['mail']['backend'],
30                                                                  ($config['mail']['params']) ? $config['mail']['params'] : array());
31                 if (PEAR::isError($backend)) {
32                         common_server_error($backend->getMessage(), 500);
33                 }
34         }
35         return $backend;
36 }
37
38 # XXX: use Mail_Queue... maybe
39
40 function mail_send($recipients, $headers, $body) {
41         $backend = mail_backend();
42         assert($backend); # throws an error if it's bad
43         $sent = $backend->send($recipients, $headers, $body);
44         if (PEAR::isError($sent)) {
45                 common_server_error($sent->getMessage(), 500);
46         }
47 }
48
49 function mail_notify_from() {
50         global $config;
51         if ($config['mail']['notifyfrom']) {
52                 return $config['mail']['notifyfrom'];
53         } else {
54                 return $config['site']['name'] . ' <noreply@'.$config['site']['server'].'>';
55         }
56 }
57
58 # For confirming a Jabber address
59
60 function mail_confirm_address($code, $nickname, $address) {
61         $recipients = $address;
62         $headers['From'] = mail_notify_from();
63         $headers['To'] = $nickname . ' <' . $address . '>';
64         $headers['Subject'] = _t('Email address confirmation');
65
66         $body = "Hey, $nickname.";
67         $body .= "\n\n";
68         $body .= 'Someone just entered this email address on ' . common_config('site', 'name') . '.';
69         $body .= "\n\n";
70         $body .= 'If it was you, and you want to confirm your entry, use the URL below:';
71         $body .= "\n\n";
72         $body .= "\t".common_local_url('confirmaddress',
73                                                                    array('code' => $code));
74         $body .= "\n\n";
75         $body .= 'If not, just ignore this message.';
76         $body .= "\n\n";
77         $body .= 'Thanks for your time, ';
78         $body .= "\n";
79         $body .= common_config('site', 'name');
80         $body .= "\n";
81
82         mail_send($recipients, $headers, $body);
83 }