package ONO::Lib::Mail::ToolBox;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::IO;
sub email_to_file {
#: Convert an email address to a valid, usable filename.
my $mail = lc $_[1];
$mail =~ s~\@~_AT_~g;
$mail =~ s~\.~_DOT_~g;
return $mail;
}
sub file_to_email {
#: Convert a valid, usable filename to an email address,
#: this only works if the filename contains _AT_ and _DOT_ strings.
my $mail = $_[1];
$mail =~ s~\.(.*)$~~g;
$mail =~ s~_AT_~\@~g;
$mail =~ s~_DOT_~\.~g;
return lc $mail;
}
sub mail_queue_append {
my (
$self,
$community,
$timing,
$queue,
$sub,
$email,
$data,
) = @_;
#: Append a mail to the send queue, which will be driven by the CronSync service.
#:
#: Supported timings can be found in ONO::Cron::CronSync::Bot, latest update:
#:
#: 1min
#: 5min
#: 10min
#: 15min
#: 30min
#: 1hour
#: 2hour
#: 4hour
#:
#: Each mail queue requires a config file, indicating the "Subject":
#:
#: var/community/_community_/mail_queue/config/$queue.conf
my $file = &email_to_file("",$email);
my $mail_data = $data;
$mail_data =~ s/^\s+|\s+$//g;
if ($data =~ /\n/) {
$mail_data = "";
foreach my $line (split(/\n/,$data)) {
$line =~ s/^\s+|\s+$//g;
if ($line eq "------") {
$mail_data .= qq~<div style="padding:10px"></div><div style="padding:1px;background-color:#999999"></div><div style="padding:10px"></div>~;
} else {
$mail_data .= "$line\n";
}
}
}
ONO::IO->mkpath("var/community/$community/mail_queue/$timing/$queue/$sub");
ONO::IO->append("var/community/$community/mail_queue/$timing/$queue/$sub/$file.txt",$mail_data);
ONO::IO->chmod("var/community/$community/mail_queue","777");
ONO::IO->chmod("var/community/$community/mail_queue/$timing","777");
ONO::IO->chmod("var/community/$community/mail_queue/$timing/$queue","777");
ONO::IO->chmod("var/community/$community/mail_queue/$timing/$queue/$sub","777");
ONO::IO->chmod("var/community/$community/mail_queue/$timing/$queue/$sub/$file.txt","777");
}
###############################################################################
# end of script
###############################################################################
1;
__END__