LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-09-2010, 08:07 AM   #1
Demerzel
LQ Newbie
 
Registered: Aug 2010
Posts: 23

Rep: Reputation: 15
SOLUTION for extracting pdf from e-mail


This can be very usefully for someone.
I was trying to extract pdf and encountered two major problems:
1. Server had Content-Transfer-Encoding: 7bit while perl MIME::Parser works with 8bit
2. When reading from file to array perl 5.8.8 drooped last 30 lines. So editing file was impossible.
This is solution:
Code:
#!/usr/bin/perl

use strict;
use warnings;
use Net::POP3;
use Mail::Header;
use MIME::Parser;

my $pop = Net::POP3->new("poczta",Timeout=>30)# conect to mail
				or die "Can't connect to host: $!\n";
	my $messages = $pop->login("demerzeli"=>"mail")
				or die "Can't log in: ",$pop->message,"\n";
my $last	=$pop->last();
$messages += 0;

print "inbox has $messages messages";
my $array = $pop->get(1); # write first mail to varible
$pop->quit(); #close conection
my $i=0;
foreach (@{$array}){ #varible is a pointer to array so we need to read it
	
	if($_ =~m/Content-Transfer-Encoding: 7bit/){ # MIME parser need 8bit so we will change it
		print "found";
		@{$array}[$i]="Content-Transfer-Encoding: 8bit\n";
		print $_;
	}
$i++;
}
open (OUTPUT, ">pop3.msgb");
print OUTPUT "$_" foreach (@{$array});
close(OUTPUT); 

my $outputdir = "/root/testmail/";
my $parser = new MIME::Parser;
$parser->output_dir($outputdir);
	open (MAILIN, "<pop3.msgb");
	my $entity = $parser->read(\*MAILIN); # extracting mail text and attachments
	close MAILIN;

Last edited by Demerzel; 08-09-2010 at 12:36 PM. Reason: adding comment to code
 
Old 08-09-2010, 09:41 AM   #2
TITiAN
Member
 
Registered: Mar 2008
Location: NRW, Germany
Distribution: Arch Linux, using KDE/Plasma
Posts: 392

Rep: Reputation: 49
What the f***???!!! This is what I've been looking for. Thanks mate!!

BTW: If your mail login is "demerzeli", and your password "mail", I just need the hostname ("poczta" isn't valid) in order to mess with your e-Mail account.
 
Old 08-09-2010, 10:39 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I must say I am a real novice when it comes to Perl, but for the life of me I cannot see what this script has to do with pdf???

I have read it a few times but I am guessing I will have to do some searching
 
Old 08-09-2010, 12:31 PM   #4
Demerzel
LQ Newbie
 
Registered: Aug 2010
Posts: 23

Original Poster
Rep: Reputation: 15
This script in fact will extract any attachment. I just need pdf for my self...

TITiAN I changed login and password so don't you try to be smarter then I am.

Admins could think about sticking this post somewhere to make it easy to find.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ps/pdf to djvu optimal conversion [solution found] H_TeXMeX_H Linux - Software 4 01-21-2009 11:31 AM
Need help for Mail server Solution.... ayush1440 Linux - Server 5 03-24-2008 04:53 AM
Mail Server Solution ??? OzTEXS Linux - General 3 01-02-2007 05:24 AM
Extracting mail attachment filename Jinkzer Linux - Software 3 02-28-2004 08:07 AM
Best mail solution ccool Linux - Software 4 11-25-2002 12:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration