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

In reply to Mail::IMAPTalk - Mark Unseen mails as seen once seen by vinoth.ree

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.