]>
git.proxmox.com Git - pmg-api.git/blob - PMG/Utils.pm
17 return $dbh->last_insert_id(
18 undef, undef, undef, undef, { sequence
=> $seq});
21 sub extract_filename
{
24 if (my $value = $head->recommended_filename()) {
26 if (my $decvalue = MIME
::Words
::decode_mimewords
($value)) {
27 $decvalue =~ s/\0/ /g;
28 $decvalue = trim
($decvalue);
37 my ($entity, $add_id, $id) = @_;
41 foreach my $tag (grep {/^x-proxmox-tmp/i} $entity->head->tags) {
42 $entity->head->delete ($tag);
45 $entity->head->replace('X-Proxmox-tmp-AID', $id) if $add_id;
47 foreach my $part ($entity->parts) {
48 $id = remove_marks
($part, $add_id, $id + 1);
59 foreach my $k (keys %$dh) {
62 $body =~ s/__${k}__/$v/gs;
70 my ($entity, $sender, $targets, $xforward, $me, $nodsn) = @_;
78 my $smtp = Net
::SMTP-
>new('127.0.0.1', Port
=> 10025, Hello
=> $me) ||
79 die "unable to connect to localhost at port 10025";
81 if (defined($xforward)) {
84 foreach my $attr (keys %{$xforward}) {
85 $xfwd .= " $attr=$xforward->{$attr}";
88 if ($xfwd && $smtp->command("XFORWARD", $xfwd)->response() != CMD_OK
) {
89 syslog
('err', "xforward error - got: %s %s", $smtp->code, scalar($smtp->message));
93 if (!$smtp->mail($sender)) {
94 syslog
('err', "smtp error - got: %s %s", $smtp->code, scalar ($smtp->message));
95 die "smtp from: ERROR";
98 my $dsnopts = $nodsn ?
{Notify
=> ['NEVER']} : {};
100 if (!$smtp->to (@$targets, $dsnopts)) {
101 syslog
('err', "smtp error - got: %s %s", $smtp->code, scalar($smtp->message));
102 die "smtp to: ERROR";
106 #$entity->sync_headers ();
109 my $out = PMG
::SMTPPrinter-
>new($smtp);
110 $entity->print($out);
112 # make sure we always have a newline at the end of the mail
113 # else dataend() fails
114 $smtp->datasend("\n");
116 if ($smtp->dataend()) {
117 my @msgs = $smtp->message;
118 $resmess = $msgs[$#msgs];
119 ($resid) = $resmess =~ m/Ok: queued as ([0-9A-Z]+)/;
120 $rescode = $smtp->code;
122 die sprintf("unexpected SMTP result - got: %s %s : WARNING", $smtp->code, $resmess);
125 my @msgs = $smtp->message;
126 $resmess = $msgs[$#msgs];
127 $rescode = $smtp->code;
128 die sprintf("sending data failed - got: %s %s : ERROR", $smtp->code, $resmess);
133 $smtp->quit if $smtp;
136 syslog
('err', $err);
139 return wantarray ?
($resid, $rescode, $resmess) : $resid;