Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8670331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:41:08+00:00 2026-06-12T18:41:08+00:00

I am using Perl to read messages, look for and save attachments. Attachments will

  • 0

I am using Perl to read messages, look for and save attachments. Attachments will always be binary pdf documents and there will never be more than one attachment. I need to read the subject, check for and save an attachment (if exists) an copy message to a folder for temporary storage.

The reading, printing, copying functions all work. I’ve tried a lot of different scenarios with MIME::Parser (I have MIME::Tools installed) but either get a blank file or file with 1 or 2 characters. I’d also like to know how to determine / set the file extension rather than just blindly rename to .pdf.

#!/usr/bin/perl


use Net::IMAP::Simple::SSL;
use Email::Simple;
use MIME::Parser;

print "Content-type: text/html\n\n";

$server = new Net::IMAP::Simple::SSL('xxx');
$server->login('xxx','xxx');

my $folder='inbox';

my ($unseen, $recent, $total) = $server->status($folder);
my $newm = $server->select('INBOX');

my $tmp=($total-9); #limit for testing

my $outputdir = "./temp";
my $parser = new MIME::Parser;
$parser->output_dir($outputdir);


for (my $i = $tmp; $i <= $total; $i++) {

        if ($server->seen($i)) {
        print "Message #$i has been seen before...<br />";
        } else {

        my $es=Email::Simple->new(join '', @{$server->top($i)});
        print $es->header('Subject')." on ";
        print $es->header('Date')."<br />";
        print "You've just seen message #$i<br />" if $server->see($i)."<br />";
        $msg = $server->get($i);
        $parser->parse_data($msg);
        $server->copy($i,'dump');

        }

    }

 $server->quit();

 exit;

Error

parse_data: wrong argument ref type: Net::IMAP::Simple::_message at mailextract.pl line x

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:41:09+00:00Added an answer on June 12, 2026 at 6:41 pm

    Don’t know why you’re using two different parsers…

    my $entity = $parser->parse_data($message);
    my $from = $entity->head->get('From');
    my $subject = $entity->head->get('Subject');
    my $timestamp = $entity->head->get('Date');
    
    for my $part ($entity->parts()) {
      if ( $part->mime_type eq 'application/pdf' ) { ### Few different types in use, see what your
                                                     ###  messages get sent with
        my $filename = $part->bodyhandle->path;
        ...
        ### Do whatever
      }
    }
    

    Edit: And your error is happening because you’re not feeding through the correct thing to be parsed, a Net::IMAP::Simple::_message instead of:

    parse_data DATA

    Instance method. Parse a MIME message that's already in core. This internally creates an "in memory" filehandle on a Perl scalar value
    

    using PerlIO

    You may supply the DATA in any of a number of ways...
    
        A scalar which holds the message. A reference to this scalar will be used internally.
    
        A ref to a scalar which holds the message. This reference will be used internally.
    
        DEPRECATED
    
        A ref to an array of scalars. The array is internally concatenated into a temporary string, and a reference to the new
    

    string is used internally.

        It is much more efficient to pass in a scalar reference, so please consider refactoring your code to use that interface instead.
    

    If you absolutely MUST pass an array, you may be better off using
    IO::ScalarArray in the calling code to generate a filehandle, and
    passing that filehandle to parse()

    Try $parser->parse($server->getfh($i));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a binary file using perl. In the file's headers, there's 4 bytes
I'm trying to read data from SQL Server database using Perl and the DBI
While using perl debugger, is there any way to step out of the current
I am using Perl to read UTF-16LE files in Windows 7. If I read
Okay, so I'm using perl to read in a file that contains some general
From everything I've read on using Perl modules, the basic usage is: Module file
I am trying to learn perl programming and am using it to read a
I have a perl script read Excel file and parse using a perl module
I am using Perl to print some data read from one file to another.
how to read the multiple values from XML file using perl script? i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.