Skip to content

Instantly share code, notes, and snippets.

@pdf
Created September 3, 2013 03:31
Show Gist options
  • Select an option

  • Save pdf/6419454 to your computer and use it in GitHub Desktop.

Select an option

Save pdf/6419454 to your computer and use it in GitHub Desktop.
mailq parse example
msgs = {}
state = nil
id = nil
mqstdout.each_line do |line|
line.strip!
case
when state.nil? && /^(?<msgid>[0-9A-F]+)\s+(?<size>[0-9]+)\s+(?<date>.+[^\s])\s+(?<sender>[^\s]+)$/ =~ line
id = msgid
msgs[id] = {
size: size.to_i,
date: date,
sender: sender
}
state = :meta
when state == :meta
msgs[id][:reason] = line
state = :reason
when state == :reason
msgs[id][:recipient] = line
state = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment