# File lib/fastcst/command/mail.rb, line 125
125:         def run
126:             pop = Net::POP3.new(@server, @port)
127:             pop.start(@user, @pass)
128:             
129:             fcst_msg_count = 0
130:             
131:             if pop.mails.empty?
132:                 UI.event :mail, "No messages available in your POP3 account."
133:             else
134:                 inbox = File.open(@mbox, "w+")
135:                 
136:                 # get the current FCST changeset ids and then go to the end 
137:                 ids = get_current_ids(inbox)
138:                 inbox.seek(0, IO::SEEK_END)
139:                 
140:                 pop.each_mail do |m|
141:                     data = m.header
142:                     msg = RMail::Parser.read(data)
143:                     
144:                     if msg.header[Distribution::X_FASTCST_ID]
145:                         fcst_msg_count += 1
146: 
147:                         # we skip message that we already have downloaded
148:                         if ids[msg.header[Distribution::X_FASTCST_ID]]
149:                             UI.event :duplicate, "#{msg.header['Subject']}\n- #{msg.header[Distribution::X_FASTCST_ID]} already in your inbox"
150:                         elsif @repo.find_meta_data(msg.header[Distribution::X_FASTCST_ID])
151:                             UI.event :duplicate, "#{msg.header['Subject']}\n- #{msg.header[Distribution::X_FASTCST_ID]} already in your repository"
152:                         elsif msg.header[Distribution::X_FASTCST_PROJECT_NAME] != @repo['Project']
153:                             UI.event :project, "#{msg.header['Subject']}\n- For project #{msg.header[Distribution::X_FASTCST_PROJECT_NAME]} not this one."
154:                             next
155:                         else
156:                             UI.event :from, "#{msg.header['From']}"
157:                             UI.event :subject, "#{msg.header['Subject']}"
158:                             UI.event :id, "#{msg.header[Distribution::X_FASTCST_ID]}"
159:                             
160:                             inbox.write("From #{msg.header['From']} #{Time.now}")
161:                             inbox.write("\n")
162:                             inbox.write(m.pop.tr("\r", ''))
163:                             inbox.write("\n")
164:                             
165:                             # must update our ids so we don't add duplicates of ones we just added
166:                             ids[msg.header[Distribution::X_FASTCST_ID]] = true
167:                         end
168:                         
169:                         if @delete
170:                             UI.event :warn, "Deleting message."
171:                             m.delete
172:                         end
173:                     else
174:                         UI.event :skipped, "#{msg.header['From']}"
175:                     end
176:                 end
177:                 
178:                 inbox.close
179:                 
180:                 puts "#{fcst_msg_count} FastCST messages out of #{pop.mails.size} mails processed."
181:             end
182:             
183:             pop.finish
184:         end