summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Model/WriteMails.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/JWebmail/Model/WriteMails.pm')
-rw-r--r--lib/JWebmail/Model/WriteMails.pm28
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/JWebmail/Model/WriteMails.pm b/lib/JWebmail/Model/WriteMails.pm
index 751192a..330f709 100644
--- a/lib/JWebmail/Model/WriteMails.pm
+++ b/lib/JWebmail/Model/WriteMails.pm
@@ -1,21 +1,15 @@
package JWebmail::Model::WriteMails;
-use v5.24;
-use warnings;
-use utf8;
-
-use JWebmail::Config 'SENDMAIL';
-
-use Exporter 'import';
-our @EXPORT_OK = qw(sendmail);
-
use Email::MIME;
+use namespace::clean;
+use Mojo::Base -base;
-our $Block_Writes = 0;
+has 'sendmail_bin';
sub _build_mail {
+ my $self = shift;
my $mail = shift;
my $text_part = Email::MIME->create(
@@ -51,9 +45,9 @@ sub _build_mail {
sub _send {
- my ($mime, @recipients) = @_;
+ my ($self, $mime, @recipients) = @_;
- open(my $m, '|-', SENDMAIL, '-i', @recipients)
+ open(my $m, '|-', $self->sendmail_bin, '-i', @recipients)
or die 'Connecting to sendmail failed. Is it in your PATH?';
$m->print($mime->as_string());
close($m);
@@ -62,21 +56,17 @@ sub _send {
sub sendmail {
+ my $self = shift;
my $mail = shift;
- my $mime = _build_mail($mail);
+ my $mime = $self->_build_mail($mail);
my @recipients;
push @recipients, @{ $mail->{to} } if $mail->{to};
push @recipients, @{ $mail->{cc} } if $mail->{cc};
push @recipients, @{ $mail->{bcc} } if $mail->{bcc};
- if ($Block_Writes) {
- say $mime;
- return 1;
- }
-
- return _send($mime, @recipients);
+ return $self->_send($mime, @recipients);
}