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 6190241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:33:09+00:00 2026-05-24T02:33:09+00:00

i have a problem with perl. i want to parse an email object or

  • 0

i have a problem with perl. i want to parse an email object or log or file whatever. i want to find where is mail comes from. first i have to check “x-envelop-from” line, if there isn’t match, then i have to check “from” line.

this is some of my sample file:

X-Envelope-From: 
    <kamil@yahoo.com>
From: "=?iso-8859-9?B?RXYgVGH+/W1hY/1s/fD9bmRhIsdfyhjdbmRRmltIFNlem9u?=
    =?iso-8859-9?B?dQ==?=" <kamil@yahoo.com>

my code prints 2 lines for this file:

kamil@yahoo.com
kamil@yahoo.com

hoe can be possible, both print lines are printed in if and elsif? is there a problem at checking matches?

while ( $line = <FILE>) 
{
    my ($from, $to, $spam_id, $date, $tmp_date, $m_day, $m_mon, $m_year, $m_hour, $m_min, $pos_tmp);
    my ($subject);
# 
    if ( $line =~ m/^(X-Envelope-From:).*/ ) {
        if ( $line =~ m/^X-Envelope-From:.*<(.*)>.*/ ) {
            $from = $1;
        }
        else {
            $line = <FILE>;
            if ( $line =~ m/.*<(.*)>.*/ ) {
                $from = $1;
            }
        }
        print $from . "\n";
    }

    elsif ( $line =~ m/^(From:).*/ ) {
        if ( $line =~ m/^From:.*<(.*)>.*/ ) {
            $from = $1;
        }
        else {
            $line = <FILE>;
            if ( $line =~ m/.*<(.*)>.*/ ) {
                $from = $1;
            }
        }
        print $from . "\n";
    }
}

thanks in advance.

  • 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-05-24T02:33:10+00:00Added an answer on May 24, 2026 at 2:33 am

    Use a specialised module such as Email::MIME to parse the headers:

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    use Email::MIME;
    
    my $em = Email::MIME->new(
        do { local $/; <DATA> }
    );
    
    my $from = $em->header('X-Envelope-From');
    $from = $em->header('From') unless $from;
    
    $from =~ s{.*<|>.*}{}g;
    print $from;
    
    __DATA__
    X-Envelope-From: 
        <kamil@yahoo.com>
    From: "=?iso-8859-9?B?RXYgVGH+/W1hY/1s/fD9bmRhIsdfyhjdbmRRmltIFNlem9u?=
        =?iso-8859-9?B?dQ==?=" <kamil@yahoo.com>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the following code (Perl/Cygwin) #!/usr/bin/perl open FILE, >, filename.txt
Hi i am new with perl i have a problem to save text from
I have an interesting problem. I wrote the following perl script to recursively loop
My problem is: I have a perl script which uses lot of memory (expected
I'm having a little problem with nginx and the Perl FCGI module. I have
I have problem with return statment >.< I want to store all magazine names
I have a perl script (or any executable) E which will take a file
I need help with a RegEx problem: I want to find occurences of two
I have a perl script that uses the CGI::Session::Drive::memcached, but I want to be
I'd like a native way to fix this problem... I have a perl command

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.