The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

GMail::Checker - Wrapper for Gmail accounts

VERSION

1.04

SYNOPSIS

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);

DESCRIPTION

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.

METHODS

The implemented methods are :

new

Creates the wrapper object.

The IO::Socket::SSL object is stored as $object->{SOCK}.

It currently only accepts username and password as hash options.

USERNAME

Your GMail account username (without @gmail.com).

PASSWORD

Your GMail password.

Returns 1 if login is successfull otherwise it closes connection.

We are not allowing USER and PASS on transaction state.

get_msg_nb_size

This 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_messages

Alerts you when you have new mails in your mailbox.

It takes as a hash argument ALERT which can have two values :

NEW_MSG_ONLY

Gives you only the number of new messages that have arrived in your mailbox since the last check.

TOTAL_MSG

Gives you the total number of messages and the actual size of the mailbox prettily formatted.

Returns a formatted string.

get_msg_size

This 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_msg

Retrieves 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 :

MSG

The message number

DELETE

Deletes 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 :

headers

The mail headers.

body

The mail body containing the message in case of a multipart message or the entire body if Content-Type holds something else.

content

The content type

<opttype>

The option type for the content-type (charset, file name...)

opt

The option value

encoding

The message encoding type

In case we have multipart/mixed messages we also have :

contentmsg

The message Content-Type.

opttypemsg

Same as opttype for the message, usually charset.

optmsg

opttypemsg value (e.g. us-ascii).

attachment

This 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_headers

Retrieves 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

MSG

The message number

HEADERS

Takes 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_uidl

Gets 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_file

Writes 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);
rset

If any messages have been marked as deleted by the POP3 server, they are unmarked.

close

Closes 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

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.

AUTHOR

Faycal Chraibi <fays@cpan.org>

TODO

- 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 ?

SEE ALSO

IO::Socket::SSL, WWW::GMail

7 POD Errors

The following errors were encountered while parsing the POD:

Around line 433:

=back doesn't take any parameters, but you said =back 4

Around line 468:

=back doesn't take any parameters, but you said =back 4

Around line 511:

=back doesn't take any parameters, but you said =back 4

Around line 545:

=back doesn't take any parameters, but you said =back 4

Around line 568:

=back doesn't take any parameters, but you said =back 4

Around line 596:

=back doesn't take any parameters, but you said =back 4

Around line 638:

=back doesn't take any parameters, but you said =back 4