<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,17 @@
 class MailReader &lt; ActionMailer::Base
 
   def receive(email)         
+    # If the email exists for a user in the current project,
+    # use that user as the author.  Otherwise, use the first
+    # user that is returned from the Member model
+    author = User.find_by_mail @@from_email, :select=&gt;&quot;users.id&quot;, :joins=&gt;&quot;inner join members on members.user_id = users.id&quot;,
+                              :conditions=&gt;[&quot;members.project_id=?&quot;, @@project.id]
+    
+    if author.nil?
+       author_id = (Member.find_by_project_id @@project.id).id
+    else
+        author_id = author.id
+    end
         
     issue = Issue.create(
         :subject =&gt; email.subject,
@@ -8,7 +19,7 @@ class MailReader &lt; ActionMailer::Base
         :priority_id =&gt; 3,
         :project_id =&gt; @@project.id,
         :tracker_id =&gt; 3,
-        :author_id =&gt; 2,
+        :author_id =&gt; author_id,
         :status_id =&gt; 1        
     )
     
@@ -49,6 +60,7 @@ class MailReader &lt; ActionMailer::Base
                      
             imap.search(['ALL']).each do |message_id|
               msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
+              @@from_email = from_email_address(imap, message_id)
               MailReader.receive(msg)          
               #Mark message as deleted and it will be removed from storage when user session closd
               imap.store(message_id, &quot;+FLAGS&quot;, [:Deleted])
@@ -64,34 +76,18 @@ class MailReader &lt; ActionMailer::Base
     user = User.find 2
     if attachment &amp;&amp; attachment.is_a?(Hash)
         file = attachment['file']
-#        if file.size &gt; 0
             Attachment.create(:container =&gt; obj, 
                                   :file =&gt; file,
                                   :author =&gt; user)
-#        end
         attached &lt;&lt; a unless a.new_record?
     end
     attached
   end
   
-private
-
-  def connect_to_email
-     begin
-       require 'net/imap'
-     rescue LoadError
-       raise RequiredLibraryNotFoundError.new('NET::Imap could not be loaded')
-     end
-
-     begin
-       @@config_path = (RAILS_ROOT + '/config/emailer.yml')
-       @@config = YAML.load_file(@@config_path)['mindbites'].symbolize_keys
-     end
-             
-     imap = Net::IMAP.new(@@config[:email_server], port=@@config[:email_port], usessl=@@config[:use_ssl])
-     
-     imap.login(@@config[:email_login], @@config[:email_password])
-     imap.select(@@config[:email_folder])  
+  def self.from_email_address(imap, msg_id) 
+    env = imap.fetch(msg_id, &quot;ENVELOPE&quot;)[0].attr[&quot;ENVELOPE&quot;]
+    mailbox = env.from[0].mailbox
+    host    = env.from[0].host
+    from = &quot;#{mailbox}@#{host}&quot;
   end
-
 end</diff>
      <filename>app/models/mail_reader.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,8 +9,8 @@
 # email_folder -- The folder name you would like your email messages retrieved from;
 # use_ssl -- If your email server requires you to use ssl to retrieve messages;
 #
-# THIS IS AN EXAMPLE.  REPLACE THIS WITH YOUR REAL SERVER DATA AND COPY TO: {RAILS_ROOT}/config directory
-# of your core Redmine project.
+# THIS IS AN EXAMPLE.  REPLACE THIS WITH YOUR REAL SERVER DATA AND COPY TO: {RAILS_ROOT}/config DIRECTORY
+# OF YOUR CORE REDMINE PROJECT.
 
 example_project:
     email_server: imap.gmail.com</diff>
      <filename>config/emailer.yml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>859e11d4019fae909c30c0eddf34313cd1c1ead2</id>
    </parent>
  </parents>
  <author>
    <name>Jim Mulholland</name>
    <email>jim@squeejee.com</email>
  </author>
  <url>http://github.com/rollick/redmine_ticket_emailer/commit/423049fcc379633de7d7adcea45a1420b907d7d1</url>
  <id>423049fcc379633de7d7adcea45a1420b907d7d1</id>
  <committed-date>2008-03-17T22:21:01-07:00</committed-date>
  <authored-date>2008-03-17T22:21:01-07:00</authored-date>
  <message>Set author by the FROM email address if that user exists in the project.</message>
  <tree>b4d27dbf5c9b054dda7d0ba6e083361391f790cd</tree>
  <committer>
    <name>Jim Mulholland</name>
    <email>jim@squeejee.com</email>
  </committer>
</commit>
