@ -95,29 +95,50 @@ class Mailer < ActionMailer::Base
# Example:
# issue_add(issue) => Mail::Message object
# Mailer.issue_add(issue).deliver => sends an email to issue recipients
def issue_add ( issue )
def issue_add ( issue , recipients )
issue_id = issue . project_index
redmine_headers 'Project' = > issue . project . identifier ,
'Issue-Id' = > issue_id ,
'Issue-Author' = > issue . author . login
redmine_headers 'Issue-Assignee' = > issue . assigned_to . login if issue . assigned_to
message_id issue
@author = issue . author
@issue = issue
@issue_url = url_for ( :controller = > 'issues' , :action = > 'show' , :id = > issue . id )
recipients = issue . recipients
cc = issue . watcher_recipients - recipients
mail :to = > recipients ,
user = User . find_by_mail ( recipients )
token = Token . new ( :user = > user , :action = > 'autologin' )
token . save
@token = token
@issue_url = url_for ( :controller = > 'issues' , :action = > 'show' , :id = > issue . id , :token = > @token . value )
# edit
@issue_author_url = url_for ( user_activities_url ( @author , :token = > @token . value ) )
@project_url = url_for ( :controller = > 'projects' , :action = > 'show' , :id = > issue . project_id , :token = > @token . value )
@user_url = url_for ( my_account_url ( user , :token = > @token . value ) )
cc = issue . watcher_recipients - issue . recipients
subject = " [ #{ issue . project . name } - #{ issue . tracker . name } # #{ issue_id } ] ( #{ issue . status . name } ) #{ issue . subject } "
mail ( :to = > recipients ,
:cc = > cc ,
:subject = > " [ #{ issue . project . name } - #{ issue . tracker . name } # #{ issue_id } ] ( #{ issue . status . name } ) #{ issue . subject } "
:subject = > subject )
end
# issue.attachments.each do |attach|
# attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}")
# end
# cc = issue.watcher_recipients - recipients
#mail.attachments['test'] = File.read("#{RAILS.root}/files/2015/01/150114094010_libegl.dll")
# Builds a Mail::Message object used to email recipients of the edited issue.
#
# Example:
# issue_edit(journal) => Mail::Message object
# Mailer.issue_edit(journal).deliver => sends an email to issue recipients
def issue_edit ( journal )
def issue_edit ( journal ,recipients )
issue = journal . journalized . reload
issue_id = issue . project_index
redmine_headers 'Project' = > issue . project . identifier ,
@ -127,18 +148,42 @@ class Mailer < ActionMailer::Base
message_id journal
references issue
@author = journal . user
recipients = journal . recipients
user = User . find_by_mail ( recipients )
token = Token . new ( :user = > user , :action = > 'autologin' )
token . save
@token = token
# edit
@issue_author_url = url_for ( :controller = > 'users' , :action = > 'show' , :id = > issue . author_id , :token = > @token . value )
@project_url = url_for ( :controller = > 'projects' , :action = > 'show' , :id = > issue . project_id , :token = > @token . value )
@user_url = url_for ( my_account_url ( user , :token = > @token . value ) )
@issue_url = url_for ( :controller = > 'issues' , :action = > 'show' , :id = > issue . id , :anchor = > " change- #{ journal . id } " , :token = > @token . value )
# Watchers in cc
cc = journal . watcher_recipients - recipients
cc = journal . watcher_recipients - journal . recipients
s = " [ #{ issue . project . name } - #{ issue . tracker . name } # #{ issue_id } ] "
s << " ( #{ issue . status . name } ) " if journal . new_value_for ( 'status_id' )
s << issue . subject
@issue = issue
@journal = journal
@issue_url = url_for ( :controller = > 'issues' , :action = > 'show' , :id = > issue , :anchor = > " change- #{ journal . id } " )
mail :to = > recipients ,
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
mail ( :to = > recipients ,
:cc = > cc ,
:subject = > s
:subject = > s )
end
def self . deliver_mailer ( to , cc , subject )
mail :to = > to ,
:cc = > cc ,
:subject = > subject
end
# 用户申请加入项目邮件通知
@ -615,5 +660,15 @@ class Mailer < ActionMailer::Base
Rails . logger
end
def add_attachments ( obj )
if email . attachments && email . attachments . any?
email . attachments . each do | attachment |
obj . attachments << Attachment . create ( :container = > obj ,
:file = > attachment . decoded ,
:filename = > attachment . filename ,
:author = > user ,
:content_type = > attachment . mime_type )
end
end
end
end