Hello all!

I made up a script for a taxi company to order a taxi. Everything is
working. I have only problems to attach an iCal event, so that you
only have to click on it and it is in your iCalendar.

The shortened script for mailing an attached file for the iCal event
is doing nothing, without any error (script 2). The other script 1 is
working. I don't understand why.

Could somebody please tell me, how can I see into a FILEHANDLE in Perl
debugger? I tried with > x <SENDMAIL> but I get only "empty array".

Thank you for your help

marek



***Script 1***

#!/usr/bin/perl

# Inspired from: http://wiki.perl-community.de/Wissensbasis/SendmailAttachments


use strict;
use warnings;
use MIME::Base64;

my $file_path = "/Users/you/Documents/webpages/cgi-bin/tmp";
my $file_name = "ical_summary.ics";

open(M, "|/usr/sbin/sendmail -t -oi") or die "Can't open mailprogram:
'/usr/sbin/sendmail'!\n$!";
print M "MIME-Version: 1.0\n";
print M qq(To: Your Name <you\@yourdomain.com>\n);
print M qq(From: Your Name <you\@yourdomain.com>\n);
print M qq(Reply-to: Your Name <you\@yourdomain.com>\n);
print M "Subject: E-Mail - the corrected version!\n";
my $boundary = "==========".substr(pack('u', ('E-Mail'.'Your Name')),
0, 24);
print M qq(Content-type: multipart/mixed; boundary="$boundary"\n);
print M qq(--$boundary\nContent-Type: text/plain;
charset="UTF-8"\nContent-Transfer-Encoding: 7bit\n\n);
print M qq(\nAnd there is a test again!\n);
print M "\n--$boundary\n";
print M qq(Content-type: application/octet-stream;
name="$file_name"\n);
print M "Content-Transfer-Encoding: base64\n";
print M qq(Content-Disposition: attachment;\nContent-Type: text/
calendar filename="$file_name"\nContent-Transfer-Encoding: base64\n);
open(F, "$file_path/$file_name") or die "Can't open data: '$file_path/
$file_name'!\n$!";
my $data;

{
binmode F;
local $/;
$data = <F>;
}
close(F) or die "Can't close: '$file_path/$file_name'! $!\n";
my $codiert = MIME::Base64::encode($data);
print M "\n$codiert\n";
print M qq(\n--$boundary--\n);
close(M) or die "Can't close the filehandle <M>: $!";

__END__


***Script 2*****

#! /usr/bin/perl

use strict;
use warnings;

use MIME::Base64;

my $mailprog = '/usr/sbin/sendmail -t -oi';
my $postmaster = 'y...@yourdomain.com';
my @recipients = ( 'i...@anothedomain.de', 'ma...@yourdomain.com' );

my $ical_data_start = "20120601T210000";
my $ical_data_end = "20120601T220000";
my $ical_summary = "Dinner";
my $ical_location = "Hörwartstr";
my $ical_file_name = $ical_summary . ".ics";

my $ical_data = <<"EOICAL";
BEGIN:VCALENDAR
BEGIN:VEVENT
DTEND;TZID=Europe/Berlin:$ical_data_end
SUMMARY:$ical_summary
DTSTART;TZID=Europe/Berlin:$ical_data_start
DTSTAMP:20120521T190638Z
LOCATION:$ical_location
SEQUENCE:0
BEGIN:VALARM
TRIGGER:-PT1H
DESCRIPTION:Event reminder
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR
EOICAL

$ical_data = encode_base64($ical_data);

my $reply = '"Your Name" <y...@yourdomain.com>';
my $from = $reply;
my $subject = "Abholung vom 1.6.2012, 21:00";
my $body = "This is a test :-) Corrected Version! You really have to
pay attention to the line endings between the different headers!\n\tda
maaki";
my $boundary = "=====" . time() . "=====";

foreach my $to (@recipients) {
my $result;
eval {
local $SIG{__DIE__};
$result = open SENDMAIL, "| $mailprog";
};
if ($@) {
die $@ unless $@ =~ /Insecure directory/;
delete $ENV{PATH};
$result = open SENDMAIL, "| $mailprog";
}

die "Can't open mailprog [$mailprog]\n" unless $result;

my $data = <<"EOMAIL";
MIME-Version: 1.0
From: $from
To: $to
Reply-to: $reply
Subject: $subject
Content-Type = multipart/mixed; boundary="$boundary"

--$boundary
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

$body
--$boundary
Content-Disposition: attachment;
Content-Type: text/calendar filename="$ical_file_name"
Content-Transfer-Encoding: base64

$ical_data

--$boundary--
EOMAIL

print SENDMAIL $data or die "write to sendmail pipe: $!";
close SENDMAIL or die "Closing of SENDMAIL failed: $!";
}


--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/


Reply via email to