1 class KwestieMailer < ActionMailer::Base
3 # Generic Receive Mail method
5 # 1. identify the reporter sending mail
6 # 1a. create a user for reporter if no account exists with that mail
7 # 2. identify and process the mail as either
9 # 2b. a comment on a current issue
12 # 1. identify the sender
13 User.current_user = find_user_from_email(email)
15 # 2. if we find the issue the email is a comment response, otherwise we have a new issue
16 issue = Issue.find_or_create_by_id(issue_id_from_email(email))
19 # 2a. process the email into the issue
20 process_issue_from_email(issue, email)
22 # 2b. process the email into a comment for this issue
23 process_comment_from_email(issue, email)
28 def process_comment_from_email(issue, email)
29 comment = issue.comments.create( { :description => email.body, :issue_id => issue.id } )
31 if email.has_attachments?
32 for attachment in email.attachments
33 comment.attachments.create({ :uploaded_data => attachment })
40 def process_issue_from_email(issue, email)
41 issue.update_attributes( { :description => email.body, :title => email.subject } )
43 if email.has_attachments?
44 for attachment in email.attachments
45 issue.attachments.create({ :uploaded_data => attachment })
54 #FIXME: this creates a user on the fly but needs a little more love to be ok
55 def find_user_from_email(email)
56 for mail in email.from_addrs
57 user = User.find_or_create_by_mail(mail)
58 return user if ! user.nil?
63 # FIXME: doesn't handle the CC address
64 def issue_id_from_email(email)
65 for mail in email.to_addrs
66 id = mail.spec.split('@')[0].split('+')[1]
67 return id if ! id.nil?