Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Attach iCal event to an cgi mail

12 views
Skip to first unread message

Marek

unread,
Jun 4, 2012, 1:37:35 PM6/4/12
to beginn...@perl.org

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 = ( 'in...@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: $!";
}

Peter Scott

unread,
Jun 7, 2012, 12:19:43 AM6/7/12
to beginn...@perl.org
On Mon, 04 Jun 2012 10:37:35 -0700, Marek wrote:

> 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".

That filehandle is open for *output* in your program! What is it you
want to examine?

--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

ms...@podiuminternational.org

unread,
Jun 7, 2012, 3:59:20 PM6/7/12
to beginn...@perl.org, beginn...@perl.org
Hello Peter!

Thank you for your reply!
Meanwhile my sendmail is working! Was quite difficult to program it.

Yes the Filehandle is opened for writing. Is there any means to look inside? How to redirect the content of SENDMAIL in the debugger?

Greetings from Munich - heavy thunderstorm here


marek

Peter Scott

unread,
Jun 10, 2012, 3:51:30 PM6/10/12
to beginn...@perl.org
After your program has opened SENDMAIL, open it again in the debugger to
wherever you want (e.g., open SENDMAIL, '>&STDOUT'). Since it's a
bareword filehandle, you'll be reopening the same one.

On Thu, 07 Jun 2012 12:59:20 -0700, mstep wrote:
> Yes the Filehandle is opened for writing. Is there any means to look
> inside? How to redirect the content of SENDMAIL in the debugger?
>
0 new messages