summaryrefslogtreecommitdiff
path: root/lib/Config/ClawsMail/Account.pm
blob: 2c538a2bce16128c136a024069501c30c136f446 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package Config::ClawsMail::Account; 
use Moo;
# VERSION 
use 5.020;
use Types::Standard qw(Str InstanceOf);
use Config::ClawsMail::Server;
use namespace::clean;
 
# ABSTRACT: Claws-Mail account 
 
has [qw(account_name name address)] => (
    is => 'ro',
    required => 1,
    isa => Str,
);
 
has [qw(imap smtp)] => (
    is => 'ro',
    isa => InstanceOf['Config::ClawsMail::Server'],
);
 
my @ssl_string=qw(no ssl starttls);
sub new_from_config {
    my ($class,$config,$password) = @_;
    return unless $config->{protocoleq '1';
 
    my $imap_server = Config::ClawsMail::Server->new({
        host => $config->{receive_server},
        port => (
            $config->{set_imapport}
                $config->{imap_port}
                $config->{ssl_imap} == 1
                scalar getservbyname('imaps','tcp')
                scalar getservbyname('imap','tcp')
            ),
        ssl => $ssl_string[$config->{ssl_imap}],
        %{$config}{qw(user_id)},
        password => $password->{recv},
    });
 
    my $smtp_server = Config::ClawsMail::Server->new({
        host => $config->{smtp_server}||$config->{receive_server},
        port => (
            $config->{set_smtpport}
                $config->{smtp_port}
                $config->{ssl_smtp} == 1
                scalar getservbyname('smtps','tcp')
                scalar getservbyname('smtp','tcp')
            ),
        ssl => $ssl_string[$config->{ssl_smtp}],
        $config->{use_smtp_auth} ? (
            user_id => $config->{smtp_user_id} || $config->{user_id},
            password => $password->{send} || $password->{recv},
        ) : () ),
    });
 
    return $class->new({
        %{$config}{qw(account_name name address)},
        imap => $imap_server,
        smtp => $smtp_server,
    });
}
 
sub email_transport {
    my ($self) = @_;
 
    require Email::Sender::Transport::SMTPS;
    my $smtp = $self->smtp;
    return Email::Sender::Transport::SMTPS->new(
        host => $smtp->host,
        port => $smtp->port,
        ssl => $smtp->ssl,
        $smtp->user_id ? (
            sasl_username => $smtp->user_id,
            sasl_password => $smtp->cleartext_password,
        ) : () )
    );
}
 
1;