📄 email.pm
字号:
################################################################################ Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.# sits@users.sourceforge.net## This program is free software; you can redistribute it and modify it under# the terms of the GPL.# Topic Listener for email notification. All email sent from Codestriker# is sent from this file when an topic event happens.use strict;package Codestriker::TopicListeners::Email;use MIME::QuotedPrint qw(encode_qp);use Net::SMTP;use MIME::Base64;use Sys::Hostname;use Encode qw(encode);use Codestriker::TopicListeners::TopicListener;# Separator to use in email.my $EMAIL_HR = "--------------------------------------------------------------";# If true, just ignore all email requests.my $DEVNULL_EMAIL = 0;@Codestriker::TopicListeners::Email::ISA = ("Codestriker::TopicListeners::TopicListener");sub new { my $type = shift; # TopicListener is parent class. my $self = Codestriker::TopicListeners::TopicListener->new(); return bless $self, $type;}sub topic_create($$) { my ($self, $topic) = @_; # Check if this action doesn't need to be logged. if (defined $topic->{email_event} && ! $topic->{email_event}) { return ''; } # Send an email to the document author and all contributors with the # relevant information. The person who wrote the comment is indicated # in the "From" field, and is BCCed the email so they retain a copy. my $from = $topic->{author}; my $to = $topic->{reviewers}; my $cc = $topic->{cc}; my $bcc = $topic->{author}; # Send out the list of files changes when creating a new topic. my (@filenames, @revisions, @offsets, @binary, @numchanges); $topic->get_filestable( \@filenames, \@revisions, \@offsets, \@binary, \@numchanges); # Determine if any topics are obsoleted by this topic. my $query = new CGI; my $url_builder = Codestriker::Http::UrlBuilder->new($query); my @obsolete_topic_urls = (); foreach my $obsolete_topic (@{$topic->{obsoleted_topics}}) { my $obj = Codestriker::Model::Topic->new($obsolete_topic); push @obsolete_topic_urls, $url_builder->view_url(topicid => $obsolete_topic, projectid => $obj->{project_id}); } my $obsolete_text = ""; if ($#obsolete_topic_urls >= 0) { $obsolete_text = "This topic obsoletes the following topics:\n\n"; $obsolete_text .= join("\n", @obsolete_topic_urls) . "\n\n"; } my $notes = "Description: \n" . "$topic->{description}\n\n" . $obsolete_text . "$EMAIL_HR\n\n" . "The topic was created with the following files:\n\n"; my $total_old_changes = 0; my $total_new_changes = 0; for (my $i = 0; $i <= $#filenames; $i++) { $notes .= $filenames[$i]; if (defined $numchanges[$i]) { $notes .= " {" . $numchanges[$i] . "}"; if ($numchanges[$i] =~ /^\+(\d+),\-(\d+)$/o) { $total_old_changes += $2; $total_new_changes += $1; } } $notes .= "\n"; } $notes .= "\nTotal line count: {+" . $total_new_changes . ",-" . $total_old_changes . "}\n"; return $self->_send_topic_email($topic, 1, "Created", 1, $from, $to, $cc, $bcc, $notes);}sub topic_changed($$$$) { my ($self, $user_that_made_the_change, $topic_orig, $topic) = @_; # Check if this action doesn't need to be logged. if (defined $topic->{email_event} && $topic->{email_event} == 0) { return ''; } # Not all changes in the topic changes needs to be sent out to everybody # who is working on the topic. The policy of this function is that # the following changes will cause an email to be sent. Otherwise, # no email will be sent. # # change in author - sent to the new author, old author, and the person who # made the change. # removed reviewer,cc - sent to the removed reviewer, and author if != user. # added reviwer,cc - send to the new cc, and author if != user. # any change not made by the author, sent to the author. # # If topic_state_change_sent_to_reviewers is true, then topic state changes # will be sent out to the reviewers. # Record the list of email addresses already handled. my %handled_addresses = (); # First rule, if the author is not one making the change, then the author # gets an email no matter what changed. if ( $user_that_made_the_change ne $topic->{author} || $user_that_made_the_change ne $topic_orig->{author} ) { $handled_addresses{ $topic_orig->{author} } = 1; $handled_addresses{ $topic->{author} } = 1; } # If the author was changed, then the old and new author gets an email. if ( $topic->{author} ne $topic_orig->{author}) { $handled_addresses{ $topic_orig->{author} } = 1; $handled_addresses{ $topic->{author} } = 1; } # If a reviewer gets removed or added, then they get an email. my @new; my @removed; Codestriker::set_differences( [ split /, /, $topic->{reviewers} ], [ split /, /, $topic_orig->{reviewers} ], \@new,\@removed); foreach my $user (@removed) { $handled_addresses{ $user } = 1; } foreach my $user (@new) { $handled_addresses{ $user } = 1; } # If a CC gets removed or added, then they get an email. @new = (); @removed = (); Codestriker::set_differences( [ split /, /, $topic->{cc} ], [ split /, /, $topic_orig->{cc} ], \@new,\@removed); foreach my $user (@removed) { $handled_addresses{ $user } = 1; } foreach my $user (@new) { $handled_addresses{ $user } = 1; } # Check for state changes if ($topic->{topic_state} ne $topic_orig->{topic_state} && $Codestriker::email_send_options->{topic_state_change_sent_to_reviewers}) { foreach my $user ( split /, /, $topic->{reviewers} ) { $handled_addresses{ $user } = 1; } } my @to_list = keys( %handled_addresses ); if ( @to_list ) { return $self->send_topic_changed_email($user_that_made_the_change, $topic_orig, $topic,@to_list); } return '';}# This function is like topic_changed, except it expects a list of people# to send the email to as the last set of parameters. It diff's the two topics# and lists the changes made to the topic in the email. The caller is responsible# for figuring out if an email is worth sending out, this function is responsible# for the content of the email only.sub send_topic_changed_email { my ($self, $user_that_made_the_change, $topic_orig, $topic,@to_list) = @_; # Check if this action doesn't need to be logged. if (defined $topic->{email_event} && $topic->{email_event} == 0) { return ''; } my $changes = ""; # Check for author change. if ($topic->{author} ne $topic_orig->{author}) { $changes .= "Author changed from " . $topic_orig->{author} . " to " . $topic->{author} . "\n"; } # Check for changes in the reviewer list. my @new; my @removed; Codestriker::set_differences( [ split /, /, $topic->{reviewers} ], [ split /, /, $topic_orig->{reviewers} ], \@new,\@removed); foreach my $user (@removed) { $changes .= "The reviewer $user was removed.\n"; } foreach my $user (@new) { $changes .= "The reviewer $user was added.\n"; } # Check for changes in the cc list. @new = (); @removed = (); Codestriker::set_differences( [ split /, /, $topic->{cc} ], [ split /, /, $topic_orig->{cc} ], \@new,\@removed); foreach my $user (@removed) { $changes .= "The cc $user was removed.\n"; } foreach my $user (@new) { $changes .= "The cc $user was added.\n"; } # Check for title change. if ($topic->{title} ne $topic_orig->{title} ) { $changes .= "The title was changed to $topic->{title}.\n"; } # Check for repository change. if ($topic->{repository} ne $topic_orig->{repository}) { my $value = $Codestriker::repository_name_map->{$topic->{repository}}; $changes .= "The repository was changed to $value.\n"; } # Check for description change. if ($topic->{description} ne $topic_orig->{description} ) { $changes .= "The description was changed.\n"; } if ($topic->{project_name} ne $topic_orig->{project_name}) { $changes .= "The project was changed to $topic->{project_name}.\n"; } if ($topic->{bug_ids} ne $topic_orig->{bug_ids}) { $changes .= "The bug list was changed to $topic->{bug_ids}.\n"; } my $change_event_name = "Modified"; # Check for state changes, has to be the last check. if ($topic->{topic_state} ne $topic_orig->{topic_state} ) { if ( $changes eq "" ) { # The state change is the only thing changed. This is a common # case, so tell people in the title what state the topic is in # now. $change_event_name = $topic->{topic_state}; } $changes .= "The state was changed to $topic->{topic_state}.\n"; } # First line is naming names on who made the change to the topic. if ($user_that_made_the_change ne "") { $changes = "The following changes were made by $user_that_made_the_change.\n" . $changes } else { my $host = $ENV{'REMOTE_HOST'};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -