Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Mail::IMAPTalk - Mark Unseen mails as seen once seen

by vinoth.ree (Monsignor)
on Jun 13, 2013 at 07:45 UTC ( #1038705=perlquestion: print w/replies, xml ) Need Help??
vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

Actually I am writing a perl script to read the unseen emails from inbox using Mail::IMAPTalk and extract the attachments.

I successfully extracted the attachment files, but once the emails read from the emails server, i need to mark those emails as read so that my script will not read those emails again.

Here is the code connects with the Email server and gets the unseen emails.

sub Connection { my $imap = Mail::IMAPTalk->new( Server => $_[0], Port => $_[3], Username => $_[1], Password => $_[2], Separator => '.', RootFolder => 'Inbox', CaseInsensitive => 1, ParseOption => 'DecodeUTF8', ) || die "Connection failed. Reason: $@"; print "IMAP connection successful !\n"; # select the IMAP folder and the last not seen message $imap->select($_[4]) || die $@; my @MsgIds = $imap->search('not', 'seen'); if(@MsgIds){ foreach my $MsgId (@MsgIds) { # Fetch the message body as a MIME object my $MsgTxt = $imap->fetch($MsgId, "body[]")->{$MsgId}->{body} +|| die "Can't fetch the message !"; my $Msg = $imap->fetch($MsgId, 'envelope')->{$MsgId}->{envelop +e}; $Msg->{From} =~ s/(")|(<.*>)|(\s{2,})|(\s+$)//g; &Extract_Attachement( $MsgTxt ); } } else { die "No new message in the mailbox\n"; } } my $server = 'imap.secureserver.net'; my $username = 'xxxxxx'; my $password = 'xxxxxx'; # establish IMAP connection &Connection($server,$username,$password,143,'INBOX');

All is well

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1038705]
help
Chatterbox?
[shmem]: Lady_Aleena: what editor are you using, on what platform?
[Lady_Aleena]: shmem, geany on Debian jessie.
[shmem]: some experience with vim?
[Lady_Aleena]: None
[shmem]: I don't know geany, and don't know whether it has support for ctags.
[Lady_Aleena]: ctags?
[shmem]: ctags is a program which (recursively) extracts the symbols from source and stores them in a one-file database. This allows you to query the locations where these symbols (e.g. a subroutine name) are used anywhere in the source code tree...
[shmem]: ...from inside the editor.
[shmem]: apt-get install exuberant-ctags
[Lady_Aleena]: I think I heard vim has a big learning curve.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-04-27 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (505 votes). Check out past polls.