I need to write a perl script that should access an iamp server, fetch the latest message, and convert it to an audio file. Last week the script was working fine but this week it starts to give me the following error: mmap() failed invalid argument. I googled the error but in vain. the following is the code i am using:
#!/usr/bin/env perl use strict; use warnings; use Mail::IMAPClient; use IO::Socket::SSL; use IO::File; use Mail::IMAPClient::MessageSet; use Mail::IMAPClient::BodyStructure; use MIME::Parser; # Connect to the IMAP server via SSL my $socket = IO::Socket::SSL->new( PeerAddr => ' imap.gmail.com ', PeerPort => 993, ) or die "socket(): $@"; # Build up a client attached to the SSL socket. # Login is automatic as usual when we provide User and Password my $client = Mail::IMAPClient->new( Socket => $socket, User => 'sara.ibnelahrache', Password => 'saraibnelahrache', ) or die "new(): $@"; $client->select('INBOX'); my $i = $client->message_count; my $msgString = $client->body_string($i); my $newtxt = ''; my $parser = new MIME::Parser; $parser->output_under('/tmp'); $parser->decode_headers(1); $parser->extract_nested_messages(0); $parser->ignore_errors(1); my $entity = $parser->parse_data($msgString); if ($entity->bodyhandle) { $newtxt = $entity->bodyhandle->as_string; } elsif ($entity->parts > -1) { $newtxt = $entity->parts(0); } else { $newtxt = "Unable to parse message text!"; } my $text = qq($newtxt); my $sounddir = "/var/lib/asterisk/sounds"; my $wavefile = "$sounddir/"."message.wav"; my $wavefileAst = "$sounddir/"."message"; my $t2wp= "/opt/swift/bin/"; unless (-f $wavefile) { open(fileOUT, ">$sounddir"."/message.txt"); print fileOUT "$text"; close(fileOUT); my $execf=$t2wp."swift -f $sounddir/message.txt -p audio/channels= +1,audio/volume=70,audio/sampling-rate=8000,audio/deada$ system( +$execf); unlink($sounddir."/message.txt"); } ###################################################################### +################################################ #Say bye $client->logout();

In reply to mail::imapclient + gmail + mmap() invalid argument by sara ibn el ahrache

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.