travelynx/lib/Travelynx/Helper/Sendmail.pm

76 lines
1.9 KiB
Perl
Raw Normal View History

2019-04-02 18:10:48 +00:00
package Travelynx::Helper::Sendmail;
2023-07-03 15:59:25 +00:00
# Copyright (C) 2020-2023 Birte Kristina Friesel
2020-11-27 21:12:56 +00:00
#
2021-01-29 17:32:13 +00:00
# SPDX-License-Identifier: AGPL-3.0-or-later
2019-04-02 18:10:48 +00:00
use strict;
use warnings;
use 5.020;
Multi-backend support Squashed commit of the following: commit 92518024ba295456358618c0e8180bd8e996fdf1 Author: Birte Kristina Friesel <birte.friesel@uos.de> Date: Fri Jul 26 18:39:46 2024 +0200 add_or_update station: remove superfluos 'new backend id := old backend id' commit df21c20c6e4c86454f8a9ac69121404415217f2a Author: Birte Kristina Friesel <birte.friesel@uos.de> Date: Fri Jul 26 18:35:51 2024 +0200 revert connection targets min_count to 3 commit be335cef07d0b42874f5fc1de4a1d13396e8e807 Author: Birte Kristina Friesel <birte.friesel@uos.de> Date: Fri Jul 26 18:20:05 2024 +0200 mention backend selection in API documentation commit 9f41828fb4f18fd707e0087def3032e8d4c8d7d8 Author: Birte Kristina Friesel <derf@finalrewind.org> Date: Thu Jul 25 20:19:23 2024 +0200 use_history: not all backends provide route data in departure monitor commit 09714b4d89684b8331d0e96f564a4c7432318f70 Author: Birte Kristina Friesel <derf@finalrewind.org> Date: Thu Jul 25 20:11:44 2024 +0200 disambiguation: pass correct hafas parameter commit 8cdf1120fc32155dc6525be64601b7c10a9c7f52 Author: Birte Kristina Friesel <derf@finalrewind.org> Date: Thu Jul 25 20:11:28 2024 +0200 _checked_in: hide Zuglauf link for non-db checkins commit 7455653f541198e0e0a6d11aed421487ffdb6285 Author: Birte Kristina Friesel <derf@finalrewind.org> Date: Thu Jul 25 20:01:47 2024 +0200 debug output commit b9cda07f85601a58ea32dbdacdd5399f302db52b Author: Birte Kristina Friesel <derf@finalrewind.org> Date: Thu Jul 25 19:09:07 2024 +0200 fix remaining get_connection_targets / get_connecting_trains_p invocations commit 2759d7258c37c7498905cfe19f6b4c4f6d16bd21 Author: Birte Kristina Friesel <derf@finalrewind.org> Date: Wed Jul 24 20:50:12 2024 +0200 support non-DB HAFAS backends (WiP)
2024-07-26 16:55:58 +00:00
use Encode qw(encode);
2019-04-02 18:10:48 +00:00
use Email::Sender::Simple qw(try_to_sendmail);
use MIME::Entity;
2019-04-02 18:10:48 +00:00
sub new {
2019-04-13 15:09:10 +00:00
my ( $class, %opt ) = @_;
2019-04-02 18:10:48 +00:00
2019-04-13 15:09:10 +00:00
return bless( \%opt, $class );
2019-04-02 18:10:48 +00:00
}
sub custom {
my ( $self, $to, $subject, $body ) = @_;
2019-04-02 18:10:48 +00:00
my $reg_mail = MIME::Entity->build(
To => $to,
2020-03-14 13:57:30 +00:00
From => $self->{config}{from},
Subject => encode( 'MIME-Header', $subject ),
Type => 'text/plain',
Charset => 'UTF-8',
Encoding => 'quoted-printable',
Data => encode( 'utf-8', $body ),
2019-04-02 18:10:48 +00:00
);
if ( $self->{config}->{disabled} ) {
2019-04-02 18:10:48 +00:00
# Do not send mail in dev mode
$self->{log}->info("sendmail to ${to}: ${subject}\n\n${body}");
2019-04-02 18:10:48 +00:00
return 1;
}
return try_to_sendmail($reg_mail);
}
sub age_deletion_notification {
my ( $self, %opt ) = @_;
my $name = $opt{name};
my $email = $opt{email};
my $last_seen = $opt{last_seen};
my $login_url = $opt{login_url};
my $account_url = $opt{account_url};
my $imprint_url = $opt{imprint_url};
my $body = "Hallo ${name},\n\n";
$body
.= "Dein travelynx-Account wurde seit dem ${last_seen} nicht verwendet.\n";
$body
.= "Im Sinne der Datensparsamkeit wird er daher in vier Wochen gelöscht.\n";
$body
.= "Falls du den Account weiterverwenden möchtest, kannst du dich unter\n";
$body .= "<$login_url> anmelden.\n";
$body
.= "Durch die Anmeldung wird die Löschung automatisch abgebrochen.\n\n";
$body
.= "Falls du den Account löschen, aber zuvor deine Daten exportieren möchtest,\n";
$body .= "kannst du dich unter obiger URL anmelden, unter <$account_url>\n";
$body
.= "deine Daten exportieren und anschließend den Account löschen lassen.\n\n\n";
$body .= "Impressum: ${imprint_url}\n";
return $self->custom( $email,
'travelynx: Löschung deines Accounts', $body );
}
2019-04-02 18:10:48 +00:00
1;