#!/usr/bin/perl
use strict;
use warnings;
use Mail::IMAPClient;
use Data::Dumper;
my $msg;
my $imap = Mail::IMAPClient->new();
$imap = Mail::IMAPClient->new(
Server => "localhost",
User => "matej",
Password => "lubdkc",
UID => 1
) or die "Cannot connect to localhost as matej: $@";
$imap->select('INBOX');
my $hash = $imap->fetch_hash("RFC822.SIZE","INTERNALDATE","FLAGS","ENVELOPE");
#print Data::Dumper->Dumpxs([$hash],['$hash']);
#print "\n===============================\n";
my @folders = $imap->folders;
#print join("\n",@folders),".\n";
#print "\n===============================\n";
# or s/folders/subscribed/
@folders = $imap->folders("INBOX" . $imap->separator . "Pratele" . $imap->separator);
print join("\n",@folders),".\n";
print "\n===============================\n";
my $msgID;
my $headers;
foreach $msg (keys(%$hash)) {
$msgID = $imap->get_header($msg,"Message-Id");
print "\$msg ID = $msg\nMESSAGE-ID = $msgID\n";
$headers = $imap->parse_headers($msg,"Date","Received","Subject","To");
print "Headers = " . Data::Dumper->Dumpxs([$headers],['$headers']) . "\n";
}
## Get a list of messages in the current folder:
#my @msgs = $imap->messages or die "Could not messages: $@\n";
## Get a reference to an array of messages in the current folder:
#my $msgs = $imap->messages or die "Could not messages: $@\n";
#use Mail::IMAPClient;
# my $imap = Mail::IMAPClient->new( Server => $imaphost,
# User => $login,
# Password=> $pass,
# Uid => 1, # optional
# );
#
# $imap->select("World Domination");
# # get the flags for every message in my 'World Domination' folder
# $flaghash = $imap->flags( scalar($imap->search("ALL"))) ;
#
# # pump through sorted hash keys to print results:
# for my $k (sort { $flaghash->{$a} <=> $flaghash->{$b} } keys %$flaghash) {
# # print: Message 1: \Flag1, \Flag2, \Flag3
# print "Message $k:\t",join(", ",@{$flaghash->{$k}}),"\n";
# }