summaryrefslogtreecommitdiff
path: root/manager/library/CAcert/User/Emails.php
blob: a341cc38f5a14efe4067b3ad0060a14f2317d384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

class CAcert_User_Emails {
    private $db = null;

    public function __construct($db) {
        $this->db = $db;
    }

    /**
     * get list of email addresses by login, needed to be able to filter emails
     * @param string $addr
     * @return array
     */
    public function getEmailAddressesByLogin($addr) {
        $db = $this->db;

        /**
         * find out user id by email address
         */
        $sql = 'select users.id from users where email=?';

        $id = $db->fetchOne($sql, array($addr));

        /**
         * get secondary email addresses
         */
        $sql = 'select email.email from email where memid=?';

        $res = $db->query($sql, array($id));

        $emails = array();

        $num = $res->rowCount();
        for ($i = 0; $i < $num; $i++) {
            $row = $res->fetch(PDO::FETCH_ASSOC);
            $emails[] = $row['email'];
        }

        /**
         * get additional addresses by domains
         */
        $sql = 'select domains.domain from domains where memid=?';

        $res = $db->query($sql, array($id));
        $num = $res->rowCount();
        $variants = array('root','hostmaster','postmaster','admin','webmaster');
        for ($i = 0; $i < $num; $i++) {
            $row = $res->fetch(PDO::FETCH_ASSOC);

            foreach ($variants as $variant) {
                $emails[] = $variant . '@' . $row['domain'];
            }
        }

        // Log::Log()->debug(__METHOD__ . ' addresses ' . implode(',', $emails));

        return $emails;
    }
}