Quantcast
Channel: Surfing the Luminiferous Ether » Perl
Viewing all articles
Browse latest Browse all 2

Truncated e-mail attachments of recordings with the Asterisk Gateway Interface

$
0
0

I recently wrote what I’m referring to as a “private podcast” service for Asterisk. My friends are widely distributed throughout the world. While there are some who are quite convenient to call, like those who are on the West Coast with me, others are much farther away. It’s really not that convenient to arrange times to talk to people in London or Singapore when you are in Califoria.

My “pseudopodcast” is an extension on Asterisk that prompts to record a sound file, plays it back, and then e-mails the sound file to a receipient specified by the extension. It’s implemented as an AGI script that takes arguments for the sender and receiver. The dialplan has a two-digit receiver extension that specifies the recipient. Caller ID provides the sender identification.

It’s a neat idea, and it has helped me stay in touch with several of my friends. The only problem was that I initially was sending out e-mail with the recording truncated. It would sound fine, but it would only be a few hundred kilobytes. It wasn’t a big problem because I had the original and I could mail in the traditional manner, but it was a bit annoying to have written all this automation that didn’t work.

The first thing I checked was that the file was being recorded OK. That allowed me to trace the problem to the delivery of the e-mail. After reading the documentation for Perl’s MIME::Lite module, which I used to create the message with its attachment, I discovered that MIME::Lite doesn’t do the encoding on attached files until it’s necessary. My first troubleshooting step was to write out the e-mail message that I meant to send to disk. By checking the message on disk, I could see that it looked fine. However, receivers still told me about truncated messages.

As a next step, I sent the e-mail message on to my ISP’s mail server. (I only run sSMTP on my Asterisk server because I don’t need to receive mail from the Internet.) Even that seemed to work, which validated the SMTP route between my Asterisk server and at least one Internet e-mail host. So, the problem wasn’t my ISP arbitrarily truncating the attachment.

What I realized when sending the the message “by hand” from the command prompt is that it takes a long time to send more than a megabyte through base64 encoding and SMTP. The problem was in how my AGI script was implemented. I had assumed that when I called MIME::Lite’s $message->send() operation, it would fork a copy of sSMTP and deliver the message. Almost, but not quite. When I hung up, the AGI script would be hung up, and that would kill its child processes. The reason all the attachments were about 500 kB is that was about the limit of my patience.

There’s a two-fold fix. One was to have the script call Asterisk’s Playtones() application to give me an audio indication that it was still working on sending. The second, and more important part, is to have the AGI script ignore HUP until it’s done sending the message. Problem solved!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images