
GMail::Checker - Wrapper for Gmail accounts

1.04

use GMail::Checker;
my $gwrapper = new GMail::Checker();
my $gwrapper = new GMail::Checker(USERNAME => "username", PASSWORD => "password");
# Let's log into our account (using SSL)
$gwrapper->login("username","password");
# Get the number of messages in the maildrop & their total size
my ($nb, $size) = $gwrapper->get_msg_nb_size();
# Do we have new messages ?
my $alert = $gwrapper->get_pretty_nb_messages(ALERT => "TOTAL_MSG");
# Get the headers for a specific message (defaults to last message)
my @headers = $gwrapper->get_msg_headers(HEADERS => "FULL", MSG => 74);
# Get a message size
my ($msgnb, $msgsize) = $gwrapper->get_msg_size(MSG => 42);
# Retrieve a specific message
my @msg = $gwrapper->get_msg(MSG => 23);
print $msg[0]->{content}, "\n";
print $msg[0]->{body};
# Retrieve UIDL for a message
my @uidl = $gwrapper->get_uidl(MSG => 10);

This module provides a wrapper that allows you to perform major operations on your gmail account.
You may create a notifier to know about new incoming messages, get information about a specific e-mail,
retrieve your mails using the POP3 via SSL interface.

The implemented methods are :
newCreates the wrapper object.
The IO::Socket::SSL object is stored as $object->{SOCK}.
It currently only accepts username and password as hash options.
Returns 1 if login is successfull otherwise it closes connection.
We are not allowing USER and PASS on transaction state.
get_msg_nb_sizeThis method checks your maildrop for the number of messages it actually contains and their total size.
It returns an array which consists of (nb_of_msgs, total_size).
Example :
my ($msgnb, $size) = $gwrapper->get_msg_nb_size();
or my @maildrop = $gwrapper->get_msg_nb_size();
get_pretty_nb_messagesAlerts you when you have new mails in your mailbox.
It takes as a hash argument ALERT which can have two values :
NEW_MSG_ONLYGives you only the number of new messages that have arrived in your mailbox since the last check.
TOTAL_MSGGives you the total number of messages and the actual size of the mailbox prettily formatted.
Returns a formatted string.
get_msg_sizeThis methods retrieves the messages size.
By default, it will return an array containing all the messages with message number and its size.
Given the hash argument MSG, size information will be returned for that message only.
Returns (-1,-1) if the mailbox is empty.
Example :
my @msg_sizes = $gwrapper->get_msg_size();
foreach $a (@msg_sizes) { printf "Message number %d - size : %d", $a->{nb}, $a->{size}; }
my @specific_msg_size = $gwrapper->get_msg_size(MSG => 2);
printf "Message number %d - size : %d", $specific_msg_size[0]->{nb}, $specific_msg_size[0]->{size};
get_msgRetrieves a message from your mailbox and returns it as an array of hash references [you will need to dereference it].
If no message number is specified, it will retrieve all the mails in the mailbox.
Returns an empty array if there is no message matching the request or mailbox is empty.
The method accepts as hash arguments :
MSGThe message number
DELETEDeletes the message from the server (do not specify it at all if you want to keep your mail on the server)
By default the messages are kept in the mailbox.
Do not forget to specify what happens to the mails that have been popped in your Gmail account settings.
The array contains for each element these properties :
headersThe mail headers.
bodyThe mail body containing the message in case of a multipart message or the entire body if Content-Type holds something else.
contentThe content type
The option type for the content-type (charset, file name...)
optThe option value
encodingThe message encoding type
In case we have multipart/mixed messages we also have :
contentmsgThe message Content-Type.
opttypemsgSame as opttype for the message, usually charset.
optmsgopttypemsg value (e.g. us-ascii).
attachmentThis is an array of hash references containing all the files attached to the message. They have the same options as above (body, content, encoding, opt, opttype).
Example :
my @msg = $gwrapper->get_msg(MSG => 2, DELETE => 1);
print $msg[0]->{headers}, $msg[0]->{body};
In case all messages are returned, just loop over the array to get them.
get_msg_headersRetrieves a message header and returns them as an array (one header item per line).
If no message number is specified, the last message headers will be retrieved.
The function takes two possible arguments as hashes
MSGThe message number
HEADERSTakes two values, FULL for full headers and MINIMAL for From, Subject and Date only.
Returns an empty array if there is no message matching the request or mailbox is empty.
Example :
my @headers = $gwrapper->get_msg_headers(HEADERS => "FULL", MSG => 3);
foreach $h (@headers) { print $h; }
get_uidlGets messages UIDL (unique-Id [hash] attributed to the message by the server).
Takes as a hash argument the MSG number or retrieves the UIDLs for all the messages.
Returns (-1,-1) if the mailbox is empty.
Example :
my @uidls = $gwrapper->get_uidl();
foreach $uid (@uidls) { print $uid->{nb}, " ", $uid->{hash}; }
my $spec_uid = $gwrapper->get_uidl(MSG => 1);
msg_to_fileWrites takes as argument the message number and writes it to the current directory to a file which name is the msg's uidl.
$gwrapper->msg_to_file(1);
rsetIf any messages have been marked as deleted by the POP3 server, they are unmarked.
closeCloses the connection after sending a QUIT command so the server properly switches to the UPDATE state.
It doesn't take any argument for now.

Copyright 2004 by Faycal Chraibi. All rights reserved.
This library is a free software. You can redistribute it and/or modify it under the same terms as Perl itself.

Faycal Chraibi <fays@cpan.org>

- Include charsets conversions support
- Send mails
- Search through mails body and headers
- Include mail storing/reading option
- Headers regexp argument for headers retrieval
- Correct bugs ?
