Skip to content

Instantly share code, notes, and snippets.

@theist
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save theist/606e8dbaa2d887f2afe2 to your computer and use it in GitHub Desktop.

Select an option

Save theist/606e8dbaa2d887f2afe2 to your computer and use it in GitHub Desktop.
quick script for erase any redmine mail whose ticket id matches another containing also the word "Cerrada" or "Resuelta"
require 'gmail'
require 'rfc2047'
to_remove = []
gmail = Gmail.connect(username,password)
rmine = gmail.inbox.find(:from => redmine_address)
puts "processing #{rmine.count} messages"
rmine.each do |mail|
subj = Rfc2047.decode(mail.subject)
if (subj =~ /\[[^#]+#([0-9]+)\]/)
tid = $1
puts subj
if (subj =~ /(Resuelta)|(Cerrada)/)
to_remove.push(tid)
puts tid + " will be removed"
end
end
end
rmine.each do |mail|
subj = Rfc2047.decode(mail.subject)
if (subj =~ /\[[^#]+#([0-9]+)\]/)
tid = $1
if to_remove.include?(tid)
puts "erasing " + subj
mail.delete!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment