Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

email parsing

by powerhouse (Friar)
on Oct 17, 2003 at 08:29 UTC ( [id://299955]=perlquestion: print w/replies, xml ) Need Help??

powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I probably should wait until tomorrow, but I am very tired of trying and failing at this tonight, so am seeking your wisdom, please.

I am building a newsletter for a client of mine, that will be built into his site, I am making it where they can subscribe(and unsubscribe) via clicking a link in an email, OR hitting reply to the message.

I am piping the email to a script, but keep getting this error:
pipe to |/home/user/main_files/ generated by local delivery failed

Here is the main portion of the script, that is getting the information...
use CGI qw(:standard); use Mail::Address; use MIME::Parser; use MIME::Entity; use MIME::Body; use Data::Dumper; use Mail::Sendmail; use Email::DB; # All these changed for demo purposes only $dbh = Email::DB::connect(); $_req_dir = '/home/user/main_files'; # Changed, for demo purposes. require "$_req_dir/vars.conf"; get_site_values(); # loaded from vars.conf above. %vars = Get_Page_Vars(\%vars,"subscribe_page_vars"); # Also loaded + from vars.conf print header(-type=>"plain/text"); # I have NO Idea why I did this + :o), tried it with and without, still same error :o( $parser = new MIME::Parser; $parser->ignore_errors(1); $parser->output_to_core(1); my $MIME_entity = $parser->parse(\*STDIN); my $error = ($@ || $parser->last_error); $header = $MIME_entity->head; $subject = $header->get('Subject'); $from = $header->get('From'); $cto = $header->get('To'); @to_addresses = Mail::Address->parse($cto); @from_addresses = Mail::Address->parse($from); my $address; if (@to_addresses) { $to = $to_addresses[0]->address(); } else { exit; } if (@from_addresses) { $from = $from_addresses[0]->address(); } else { exit; } if ($MIME_entity->parts > 0) { for (my $i=0;$i<$MIME_entity->parts;$i++) { my $subEntity = $MIME_entity->parts($i); my $ignore_plain = 0; my $ignore_html = 0; $ishtml = "1" if $subEntity->mime_type eq 'text/html'; $ishtml = "0" if $subEntity->mime_type eq 'text/plain'; if (($subEntity->mime_type eq 'text/html') && ($ignore_htm +l == 0)) { if (my $io = $subEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $io->close; $ignore_plain=1; } } if (($subEntity->mime_type eq 'text/plain') && ($ignore_pl +ain=0)) { if (my $io = $subEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $io->close; $ignore_html=1; } } } } else { $body = join "", @{$MIME_entity->body}; } $to = $1 if $to =~ /<(\S+)>/; if ($from =~ /<(\S+)>/) { $newfrom = $1 } else { $newfrom = $fr +om } $body =~ s/"/\"/g; if (($subject =~ /^(remove|unsubscribe)/i) || ($to =~ /(remove|rem +oval|unsubscribe)/i)) { UnSubscribe_User($from); } elsif ($subject =~ /\|/) { Subject_Parser($subject); } else { die "Could not run script! $!"; exit; }

Is there an easier way to do this, that you know of? I am so frustrated with this :o(

Thank you for any advise you can offer me.

Have a good night.

Replies are listed 'Best First'.
Re: email parsing
by ptkdb (Monk) on Oct 17, 2003 at 14:55 UTC
    I have this image of a crying, sick baby being left on a Monastery steps with a note saying, "fix this, I'll be back later."

  • More comments in the code.
  • Which parts of the code are producing the error messages?
  • What has been tried that should work but didn't?
      Hmm, Nope, did not leave expecting code to be fixed, first of all, I did not show you all the code, I was just wondering if someone knows how to do what I'm trying, and can see a BLATANT problem, that just stands out, maybe they possibly had the same problem, and know what caused it.

      That is why I came here, not for someone to fix it, but for some advice.

      So, with that said, here is my reply to your comments, that I do appreciate you giving:

      >More comments in the code.
      Ok, I'll try to work on doing that before I ever post anything.

      >Which parts of the code are producing the error messages?
      I don't know, I don't get any error message, EXCEPT the email being returned with this message:
      pipe to |/home/user/main_files/ generated by local delivery failed
      That is the ONLY error I get. Nothing in the logs, and so forth.

      >What has been tried that should work but didn't?
      Sending an email that gets piped to the script, which appears to not even be getting ran. It's almost like it errors before the script even executes. I even added a
      open(FILE,">>test.txt") or die "Could not open Test: $!"; print FILE "Got to line xx"; close(FILE);
      But test.txt was never created, almost like the script NEVER ran.
      I checked the directory permissions.
      I checked the Script permissions.
      I checked the syntax in Shell: (perl -c

      I could find NO Problem.

      I'm going to try a few things, to clean up the code, but I don't think it will help.

Re: email parsing
by mandog (Curate) on Oct 17, 2003 at 23:47 UTC

    How are you piping the email to the script?

    If you were using postfix to recieve your email, I would say that you were attempting to send mail to a pipe from inside  /etc/postfix/virtual This can't be done. Guessing wildly you need to do your piping in your alias file and send your mail to the alias.

      Well, I am on a Cpanel Machine, I'm using the forward an email feature to PIPE it to the script. It works for my HelpDesk Application.

      I simply enter the email I want the forwarder on, and put the forward to as:
      That "forward" puts it in the valiases for the domain name.


        Well, I am on a Cpanel Machine, I'm using the forward an email feature to PIPE it to the script. It works for my HelpDesk Application.

        What does "I'm using the forward an email feature" mean? Do you mean a *nix .forward file? If not, a quick explanation of what the "forward an email feature" is and what it actually does would be, er, helpful don't you think?

        -- vek --

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://299955]
Approved by robartes
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-22 08:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found