# File lib/fastcst/command/mail.rb, line 274
274:         def run
275:             still_pending = []
276:             mbox_stream = open(@mbox)
277:             
278:             RMail::Mailbox.parse_mbox(mbox_stream) do |text|
279:                 
280:                 msg = RMail::Parser.read(text)
281: 
282:                 # only process fastcst tagged messages
283:                 if msg.header[Distribution::X_FASTCST_ID]        
284:                     UI.event :from, "#{msg.header['From']}"
285:                     UI.event :subject, "#{msg.header['Subject']}"
286:                     UI.event :id, "#{msg.header[Distribution::X_FASTCST_ID]}"
287: 
288:                     if msg.multipart?
289:                         answer = UI.ask("Add this changeset to your repository (D=delete)? [D/Y/n]").downcase
290:                         
291:                         if answer == "y"
292:                             # go into the work directory, save them, and then add them to the repo
293:                             md_file = nil
294:                             
295:                             Dir.chdir @repo.work_dir do
296:                                 md_file, data_file, journal_file = load_save_changeset(msg)
297: 
298:                                 # check if this one is already in the repository
299:                                 md = MetaData.load_metadata(md_file)
300:                                 
301:                                 if @repo.find_meta_data(md['ID'])
302:                                     answer = UI.ask("This changeset is already in your repository.  Add anyway? [Y/n]").downcase
303:                                     
304:                                     if answer != "y"
305:                                         UI.failure :constraint, "Will not add this one.  Delete it using the read command again."
306:                                         return
307:                                     end
308:                                 end
309:                             end
310:                             
311:                             # store the newly created changeset, doing a move instead of a copy
312:                             md = @repo.store_changeset @repo.work_dir, md_file, move=true
313:                         elsif answer != "d"
314:                             # by the answer not being 'y' and not 'd' they want to keep this one
315:                             # in this case they answered no so we keep it
316:                             still_pending << msg
317:                         end
318:                     else
319:                         puts "ERROR: Not Multipart, bad file"
320:                         still_pending << msg
321:                     end
322:                 end
323:             end
324:             
325:             # finished processing all messages, we now have to write back 
326:             # the list of messages still_pending since these were not processed
327:             mbox_stream.close
328:             
329:             UI.start_finish("Writing remaining #{still_pending.length} messages back to inbox") do 
330:                 File.open(@mbox, "w") do |out|
331:                     still_pending.each do |msg|
332:                         out.write("From #{msg.header['From']} #{Time.now}")
333:                         out.write("\n")
334:                         RMail::Serialize.write(out, msg)
335:                         out.write("\n")
336:                     end
337:                 end
338:             end
339:             
340:         end