From 7f7f14da643b1ca7314f2cc5c0f78123683a2cee Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Wed, 25 Feb 2009 17:42:42 +1300 Subject: [PATCH] Add a new option to send birthday wishes to the email-reminder author This is disabled by default and only happens if this is set in the XML file: 1 The checkbox will be enabled by default in the GUI editor if the option is missing from the XML file. --- Changes | 1 + EmailReminder/EventList.pm | 13 +++++++++++++ email-reminder-editor | 15 ++++++++++++++- examples/email-reminders | 2 ++ send-reminders | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index e07114d..947b1ea 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ going to a third-party - no longer require the Net::SMTP::SSL module - update author email address + - option to send birthday wishes to the email-reminder author 0.7.4 (2008-11-20) - support for SSL SMTP servers diff --git a/EmailReminder/EventList.pm b/EmailReminder/EventList.pm index 5e4f111..c33b1c1 100644 --- a/EmailReminder/EventList.pm +++ b/EmailReminder/EventList.pm @@ -48,6 +48,7 @@ my $EVENTS_TAG = 'events'; my $FIRST_NAME_TAG = 'first_name'; my $LAST_NAME_TAG = 'last_name'; my $USER_TAG = 'email-reminder_user'; +my $AUTHOR_WISHES_TAG = 'send_author_wishes'; my $TYPE_ATTR = 'type'; @@ -296,6 +297,18 @@ sub set_user_lname return EmailReminder::Utils::set_node_value($self->{USER_NODE}, $LAST_NAME_TAG, $new_lname); } +sub get_author_wishes +{ + my $self = shift; + return EmailReminder::Utils::get_node_value($self->{USER_NODE}, $AUTHOR_WISHES_TAG); +} + +sub set_author_wishes +{ + my ($self, $new_author_wishes) = @_; + return EmailReminder::Utils::set_node_value($self->{USER_NODE}, $AUTHOR_WISHES_TAG, $new_author_wishes); +} + # Return 0 if the email was ignored (invalid) sub set_user_email { diff --git a/email-reminder-editor b/email-reminder-editor index eb2052d..9b2f54b 100755 --- a/email-reminder-editor +++ b/email-reminder-editor @@ -382,11 +382,21 @@ sub create_prefs_dialog $lname->set_text($fullname[1]); $email->set_text($events->get_user_email()); + my $author_wishes = Gtk2::CheckButton->new_with_label('Send birthday wishes to the email-reminder author?'); + my $existing_value = $events->get_author_wishes(); + if (defined($existing_value)) { + $author_wishes->set_active($existing_value); + } + else { + # Default to true in the UI + $author_wishes->set_active(TRUE); + } + my $name = Gtk2::HBox->new(); $name->pack_start($fname, TRUE, TRUE, 0); $name->pack_start($lname, TRUE, TRUE, 0); - my $options = Gtk2::Table->new(2, 2, FALSE); + my $options = Gtk2::Table->new(3, 2, FALSE); $options->set_row_spacings(3); $options->attach_defaults($name_label, 0, 1, 0, 1); $options->attach_defaults($name, 1, 2, 0, 1); @@ -395,14 +405,17 @@ sub create_prefs_dialog $options->show_all(); $info_label->show(); + $author_wishes->show(); $dialog->vbox->set_spacing(6); $dialog->vbox->add($info_label); $dialog->vbox->add($options); + $dialog->vbox->add($author_wishes); $dialog->signal_connect(response => sub { # Update values $events->set_user_fname($fname->get_text()); $events->set_user_lname($lname->get_text()); + $events->set_author_wishes($author_wishes->get_active() ? '1' : '0'); unless ($events->set_user_email($email->get_text())) { my $warning = Gtk2::MessageDialog->new($dialog, ['modal'], 'warning', 'ok', "The email address you entered is invalid; it has not been changed."); $warning->run(); diff --git a/examples/email-reminders b/examples/email-reminders index dd3c3e8..8796fee 100644 --- a/examples/email-reminders +++ b/examples/email-reminders @@ -6,6 +6,8 @@ Marier francois@email-reminder.org.nz +1 + diff --git a/send-reminders b/send-reminders index 85cfc6f..7608619 100755 --- a/send-reminders +++ b/send-reminders @@ -215,6 +215,44 @@ sub send_email return 1; } +sub send_author_wishes +{ + my $user_name = shift; + my $user_email = shift; + + print "--> Processing event Email-Reminder Author's Birthday\n" if $verbose; + + my $today = ParseDate('now'); + my $current_month = UnixDate($today, '%m'); + my $current_day = UnixDate($today, '%d'); + + if (1 == $current_month and 30 == $current_day) { + print "--> Event Email-Reminder Author's Birthday is occurring\n" if $verbose; + + my $recipient_name = 'Francois Marier'; + my $recipient_email = 'francois@email-reminder.org.nz'; + my $subject = 'Happy birthday from an email-reminder user'; + my $message = <<"MESSAGEEND"; +Hi Francois, + +Happy birthday and thank you for email-reminder! + +$user_name +$user_email + +-- +Sent by Email-Reminder $EmailReminder::Utils::VERSION +http://www.email-reminder.org.nz/ +MESSAGEEND + + if (!send_email($message, $subject, $recipient_name, $recipient_email)) { + return; + } + } + + return 1; +} + sub process_file { my $file = shift; @@ -262,6 +300,10 @@ sub process_file } } + if ($list->get_author_wishes()) { + send_author_wishes($user_name, $user_email); + } + return 1; } -- 2.11.4.GIT