Fetching all ‘From’ email addresses from an IMAP email account
Perl February 12th, 2008
If you want to back-up certain elements of your email account, this is not always very easy to do. For example you may not use your address book much (or never), but want to keep a backup of all of the email addresses that have sent messages to you.
Thanks to Mail::IMAPClient, this is pretty easy to do - just use the code below and add in your IMAP server, username and password details where appropriate:
PERL:
-
#!/usr/bin/perl -w
-
use strict;
-
use Mail::IMAPClient::BodyStructure;
-
use Mail::IMAPClient;
-
-
my $serv = '';
-
my $usr = '';
-
my $pwd = '';
-
-
# Open file for writing
-
-
# Log into mail account
-
-
# Select necessary folder
-
-
# Get 'From' headers from all messages and print them to file
-
for my $h (
-
) {
-
}
-
close EMAILS;
-
-
# Open file again for reading
-
-
# Root out duplicates and put into an array
-
my @seen;
-
while (<EMA2>) {
-
my $infile = $_;
-
}
-
-
-
# Print array to file, overwriting any duplicate data
-
-
foreach my $em (@seen) {
-
print EMA3 "$em\n";
-
}
-
close EMA3;






