Created
September 3, 2013 03:31
-
-
Save pdf/6419454 to your computer and use it in GitHub Desktop.
mailq parse example
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
| 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