Last active
February 18, 2025 05:59
-
-
Save EldonMcGuinness/5b241d8c65f80d3a1c551eb76a3b6157 to your computer and use it in GitHub Desktop.
Find tickets that are spam and write them to files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the tag to look for, your spam should have this tag | |
spam_tag = "spam" | |
# Where to store the eml files | |
# !!! Note that there is not a trailing slash, do not put one !!! | |
destination = "/opt/zammad/spam_tickets" | |
#find tickets with a spam tag | |
puts "Looking for Spam\r\n" | |
for ticket in Ticket.all do | |
# If the ticket has the spam tag | |
if ticket.tag_list.include?("spam") | |
# Get the current time and calculate the look_back | |
current_time = Time.zone.now | |
look_back = current_time - 7.days | |
# Make sure the email is in the needed time frame | |
if ticket.created_at > look_back && ticket.created_at <= current_time | |
# Tick to show work being done | |
print '.' | |
begin | |
# Make sure the article is not nil | |
if not ticket.articles.first.as_raw.nil? then | |
# Write the email to an eml file for later use | |
File.open("#{destination}/zammad_ticket_#{ticket.id}.eml", "wb") do |file| | |
file.write("#{ticket.articles.first.as_raw.content}") | |
end | |
end | |
rescue => e | |
# Let me know if there is an error, but don't die | |
puts "Error with ticket #{ticket.id}: #{e}" | |
end | |
end | |
end | |
end | |
puts "" | |
puts("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment