# Type: Input # Category: Config # Description: Allows to specify whether Redmine email notifications should be sent to user # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:Please )?((?:do(?:n\'t| not)|never|stop) )?notify(?:ing)?(?: me)? (?:by|using) e?-?mail(?: messages)?!*\.*$', '^(?:I )?(do(?:n\'t| not) )?(?:want) to be notified (?:by|using) e?-?mail(?: messages)?!*\.*$', '^(?:(Disable)|enable) (?:Redmine )?e?-?mail notifications!*\.*$', '^Turn (?:on|(off)) (?:Redmine )?e?-?mail notifications!*\.*$' ], handler => sub { my ($context, $user, $item, $negation) = @_; my $message; my $prefs = $main::query->GetUserPreferences($user->GetUserID); if (defined($prefs) && defined($prefs->{'no_email_notify'}) && ($prefs->{'no_email_notify'} eq 'true')) { if (defined($negation)) { $message = Orangutan::Context::Random( 'Strange... I already asked Redmine to stop notifying you!', 'Hm... Perhaps my Redmine module does not work... :S', 'You should not be receiving emails!.. :S' ); } else { $prefs->{'no_email_notify'} = 'false'; $main::query->UpdateUserPreferences($user->GetUserID, $prefs); $message = Orangutan::Context::Random('Ok... ', 'I see.. ', 'Got it... '); $message .= Orangutan::Context::Random( 'Be ready to receive emails now.', 'Emails are coming now... ;)', 'As you command...' ); } } else { if (defined($negation)) { if (!defined($prefs)) { $prefs = { }; } $prefs->{'no_email_notify'} = 'true'; $main::query->UpdateUserPreferences($user->GetUserID, $prefs); $message = Orangutan::Context::Random('Ok... ', 'Cool!.. ', 'Nice... '); $message .= Orangutan::Context::Random( 'Will ask Redmine to stop emailing you...', 'Will talk with Redmine about this...', 'Will do my best!', 'No more emails!' ); } else { $message = Orangutan::Context::Random( "It's not me if you are not receiving email notifications from Redmine!..", 'You should be receiving email notifications from Redmine...', 'I have nothing to do with this...' ); } } $user->SendMessage($message); }, onsubscription => sub { my ($context, $user, $type, $status) = @_; if ($status eq 'unsubscribe') { my $prefs = $main::query->GetUserPreferences($user->GetUserID); if (defined($prefs) && defined($prefs->{'no_email_notify'})) { delete($prefs->{'no_email_notify'}); $main::query->UpdateUserPreferences($user->GetUserID, $prefs); $main::logger->Log('removed :no_email_notify'); } } }, help => { title => 'How can I disable/enable Redmine email notifications?', question => '^(?:How )?(?:(?:can|do) I |to )(?:disable(?:/enable)?|turn (?:off|on)|enable) (?:Redmine )?e?-?mail notifications\?*!*\.*$', answer => "Orangutan is able to notify users about changes in issues and new issues. ". "The same is done by default by Redmine using email. ". "It can be annoying to receive notifications in both ways - by email and by Jabber. ". "But it's not a problem - you can disable Redmine email notifications.\n". "Samples:\n". " o Do not notify me using email messages\n". " o Turn off Redmine email notifications\n". " o Disable email notifications\n". " o Stop notifying me by email\n". "To turn email notifications back:\n". " o Enable email notifications\n". " o Notify me by email\n". "Email notifications can be turned on or off only using Orangutan...\n". "See also: How can I disable/enable notifications?", weight => 585 } ); # kate: syntax perl