The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mail::GcalReminder - Send reminders to Google calendar event guests

VERSION

This document describes Mail::GcalReminder version 0.5

SYNOPSIS

    use Mail::GcalReminder;

    my $gcr = Mail::GcalReminder->new(
        'gmail_user' => "…@gmail.com",
        'gmail_pass' => "…", # !!!! chmod 700 !!
        'app_name' => 'Acme Co, Auto Notifier',
    );

    $gcr->send_reminders({
        'gcal' => '…%40group.calendar.google.com/private-…', # !!!! chmod 700 !!
        'in_advance' => ['weeks' => 1],
        'min_events' => 1,
        'max_events' => 1,
        'subject' => "[thing schedule] 1 week reminder for you thing",
        'body' => 'Be there or be square! Call me if you have questions: 867-5309.',
    });

    $gcr->send_reminders({
        'gcal' => '…%40group.calendar.google.com/private-…', # !!!! chmod 700 !!
        'in_advance' => ['weeks' => 5],
        'min_events' => 1,
        'max_events' => 1,
        'subject' => sub {
            my ($self,$event) = @_;
            …
            return "[thing schedule] 5 week heads up for you $event->{'title'}";
        },
        'body' => sub {
            my ($self,$event) = @_;
            …
            return 'All details are in the calendar, see you in five weeks!';
       },
    });

Now simply cron that to run everyday at, say, 4am (to avoid DST blackouts) and you're done! Any problems are output as messages and will come into your cron email.

    0 4 * * * /home/me/send_talk_reminders.pl

DESCRIPTION

You can set gmail to send you reminders for stuff in your calendar but you can’t have it send reminders to guests.

This module allows you to create scripts that grab a goodle calendar and send reminders to guests from your gmail account.

INTERFACE

new() attribute/get-set methods

  • gmail_user (required in new)

    Your Gmail account user.

  • gmail_pass (required in new)

    Your Gmail account password. For security, you should protect your script (e.g. chmod 700).

  • app_name

    A name to use in the default signature().

    Defaults to: $gcr->gmail_user (__PACKAGE__)

  • cc_self

    Boolean, default 1, CC gmail_user() on each email sent.

  • try_receipts

    Boolean, default 1, try to do read receipts for each email sent.

  • try_priority

    Boolean, default 1, try to do read receipts for each email sent.

  • no_guests_is_ok

    Boolean, default 1, if an event has no guests do not count it as a failure in send_reminders(). You still get a “No guests” warning().

  • base_date

    A date time object, default DateTime->now( time_zone => $gcal->time_zone ), to base 'in_advance' on.

  • time_zone

    Time zone to use in default 'base_date' and the event_dt_obj object.

    Defaults to UTC. Value given must be sutiable for DateTime::TimeZone->new’s name attribute.

  • http

    HTTP Client object. Defaults to lazy loaded HTTP::Tiny object.

    If an object is given it must have a mirror() method.

    That mirror() method should that a URL and a file path and returns the same sort of response object as HTTP::Tiny.

  • workdir

    Directory to download ical’s too.

  • include_event_dt_obj

    Boolean, default 0, include the key event_dt_obj in the “hashref of event details”

  • essg_hax_ver

    Mostly internal, identifies a module version that we've tested a certain header behavior on, this is mostly for testing and to flag us down when the module is updated.

  • warning_code

    This is a code ref that is executed by warning(). The default it is a carp() with the proper level set.

  • date_format_obj

    Deprecated as of v0.5, due to not needing to parse ATOM feed date strings.

  • signature

    Message to append to the email body.

    Default is:

        $body
    
        --
        $gcr->app_name
    
        Note: Please ensure mail from “$gcr->gmail_user” is not being filtered out of your inbox.
  • debug

    Boolean, default 0, enables debug mode which makes things more verbose and uses gmail_user() for “to” instead of guests.

  • gcal_cache

    A hashref that contains a cache of fetched and parsed calendars. We cache so we can send different reminders (e.g. 1 week and 5 week) on the same calendar and only download and parse it once.

methods

send_reminders({…})

This sends reminders per the configuration hashref you pass in (described below).

Returns zero-but-true when there are no applicable events.

Returns the event count if all were successfully sent messages (or there were any with no guests but you've considered it ok via $gcal->no_guests_is_ok()).

Returns false otherwise. Specific messages are given to $gcal->warning().

The send_reminders() configuration hashref has the following keys:

'gcal'

The calendar whose events you are interested in.

The value is part of the XML (under “Calendar Details” in your google calendar UI).

Take the URL and remove 'https://www.google.com/calendar/feeds/' from the beggining and '/basic' from the end.

For example:

If your public XML URL is: https://www.google.com/calendar/feeds/6qrhpfk1utcs97g9u2o27g5ojo%40group.calendar.google.com/public/basic

Then the value to 'gcal' is: 6qrhpfk1utcs97g9u2o27g5ojo%40group.calendar.google.com/public

If your private XML URL is: https://www.google.com/calendar/feeds/6qrhpfk1utcs97g9u2o27g5ojo%40group.calendar.google.com/private-a6689d558b4dbba8942e510985b604d3/basic

Then the value to 'gcal' is: 6qrhpfk1utcs97g9u2o27g5ojo%40group.calendar.google.com/private-a6689d558b4dbba8942e510985b604d3';

Note: The public URL does not include guests in the data so you should probably use the private URL (or 'guestcheck' to get a list via other means). For security, you should protect your script (e.g. chmod 700).

'label'

Name to use in messages, defaults to 'gcal'.

'in_advance'

This is how we find the events we are interested in. If your your base_date is the default and you are sending remionders for 1 week 'in_advance' then any events 7 days from right now are what we are looking for.

The value is an array ref of arguments sutiable for DateTime’s add method.

'subject'

The subject of the reminder email. Either a UTF-8 string or a coderef that takes the main object and a hashref of event details (described under get_gcal()) as its arguments and returns the string.

'body'

The body of the reminder email. Either a UTF-8 string or a coderef that takes the main object and a hashref of event details (described under get_gcal()) as its arguments and returns the string.

'min_events'

Optional. The minimum number of events that should be on a given day if there are any.

'max_events'

Optional. The maximum number of events that should be on a given day if there are any.

'min_guests'

Optional. The minimum number of guests that an event is expected to have.

'max_guests'

Optional. The maximum number of guests that an event is expected to have.

'guestcheck'

Optional. A coderef that takes the main object and then any event guests as it args, does whatever you want (e.g. check that the guest is in your database and warning() otherwise, filter out certain ones, include others, etc), and returns the guest list you want to use.

Other methods that exist to support send_reminders():

  • get_gcal($gcal)

    Fetch, parse, and cache the given google calendar. Argument is the same as set_reminder’s 'gcal' key. Returns the cached hashref of event details for the given google calendar.

    The “hashref of event details” has the following keys:

    'title'

    Name of the event.

    'desc'

    Description of event. This is undef if there is no description.

    'url'

    URL of the event.

    'date'

    Stringified month and day of the event.

    'year'

    Year of the event.

    'time'

    Time of the event.

    'guests'

    An array ref of event guests.

    'location'

    The location of the event, if any.

    event_dt_obj

    This will exist if $gcr->include_event_dt_obj is true. It is a DateTime object of the event’s date/time. The time zone is $gcr->time_zone

    'gcal_title'

    Title of the calendar.

    'gcal_uri'

    URL of the calendar.

    'gcal_entry_obj'

    The events’s Data::ICal::Entry object.

    'gcal_updated'

    Raw date the calendar was last updated.

    'gcal_updated_date'

    Formatted date the calendar was last updated.

  • warning("message goes here\n");

    Handle the given message. set via warning_code().

  • send_gmail($to,$subject,$body);

    Send an email from gmail_users() account. Returns true on success. If it fails the error is sent to warning() and it returns false.

DIAGNOSTICS

All messages are sent to $gcr->warnings().

Not enough events (min %d, actual %d) for “%s”.
Too many events (max %d, actual %d) for “%s”.
Not enough guests (min %d, actual %d) for “%s”.
Too many guests (max %d, actual %d) for “%s”.
No guests for “%s”.
Could not determine date due to missing “dtstart”.
Email::Send::SMTP::Gmail is newer than $gcr->essg_hax_ver, skipping header-via-charset hack

Errors beyond those are not directly from this module.

DEPENDENCIES

Moo

Email::Send::SMTP::Gmail

DateTime

DateTime::TimeZone

Carp

DateTime::Format::ISO8601

HTTP::Tiny

XML::Simple

Temp::File

For Testing: Test::More, Net::Detect, Test::Warn

TODO

Support and/or outline how a config file might be used to various advantages.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-mail-gcalreminder@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Daniel Muey <http://drmuey.com/cpan_contact.pl>

LICENCE AND COPYRIGHT

Copyright (c) 2013, Daniel Muey <http://drmuey.com/cpan_contact.pl>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.