diff options
Diffstat (limited to 'playWithImap.pl')
-rw-r--r-- | playWithImap.pl | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/playWithImap.pl b/playWithImap.pl index e722041..de397ca 100644 --- a/playWithImap.pl +++ b/playWithImap.pl @@ -1,13 +1,61 @@ -#!/usr/bin/perl -Wall +#!/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" + Password => "lubdkc", + UID => 1 ) or die "Cannot connect to localhost as matej: $@"; -print Dumper($imap);
\ No newline at end of file + +$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"; +# } |