Guest User

Untitled

a guest
Feb 28th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1.  
  2. test = "Delivered-To: twtbot@gmail.com
  3. Received: by 10.114.155.8 with SMTP id c8cs261037wae;
  4. Thu, 22 Jan 2009 18:13:17 -0800 (PST)
  5. MIME-Version: 1.0
  6. Sender: neufelry@gmail.com
  7. Received: by 10.114.92.14 with SMTP id p14mr4207993wab.140.1232676797484; Thu,
  8. 22 Jan 2009 18:13:17 -0800 (PST)
  9. Date: Thu, 22 Jan 2009 20:13:17 -0600
  10. X-Google-Sender-Auth: ac619f32b7c737b4
  11. Message-ID: <70fc96270901221813w5e7e8946td90f532cdc57d8c3@mail.gmail.com>
  12. Subject: test
  13. From: Ryan Neufeld <rkneufeld@gmail.com>
  14. To: twtbot@gmail.com
  15. Content-Type: multipart/alternative; boundary=00163646cbf6a30f1204611cee3c
  16.  
  17. --00163646cbf6a30f1204611cee3c
  18. Content-Type: text/plain; charset=ISO-8859-1
  19. Content-Transfer-Encoding: 7bit
  20.  
  21. off
  22.  
  23. --00163646cbf6a30f1204611cee3c
  24. Content-Type: text/html; charset=ISO-8859-1
  25. Content-Transfer-Encoding: 7bit
  26.  
  27. off
  28.  
  29. --00163646cbf6a30f1204611cee3c--
  30. "
  31.  
  32. DELIVERED_TO = /^Delivered-To:/
  33. RECEIVED = /^Received:/
  34. MIME_VERSION = /^MIME-Version:/
  35. DATE = /^Date:/
  36. X_GOOGLE_SENDER_AUTH = /^X-Google-Sender-Auth:/
  37. MESSAGE_ID = /^Message-ID:/
  38. SUBJECT = /^Subject:/
  39. FROM = /^From:/
  40. TO = /^To:/
  41. CONTENT_TYPE =/^Content-Type:/
  42.  
  43. @email = {}
  44. @email[:ignore] =[]
  45. prev = :ignore
  46. test.each_line do |line|
  47. prev = case line
  48. when DELIVERED_TO
  49. (@email[:delivered_to] ||= []) << line.gsub( DELIVERED_TO , '')
  50. :delivered_to
  51. when RECEIVED
  52. (@email[:recieved] ||= []) << line.gsub( RECEIVED , '')
  53. :recieved
  54. when MIME_VERSION
  55. (@email[:mime_version] ||= []) << line.gsub( MIME_VERSION , '')
  56. :mime_version
  57. when DATE
  58. (@email[:date] ||= []) << line.gsub( DATE , '')
  59. :date
  60. when X_GOOGLE_SENDER_AUTH
  61. (@email[:x_google_sender_auth] ||= []) << line.gsub( X_GOOGLE_SENDER_AUTH , '')
  62. :x_google_sender_auth
  63. when MESSAGE_ID
  64. (@email[:message_id] ||= []) << line.gsub( MESSAGE_ID, '')
  65. :message_id
  66. when SUBJECT
  67. (@email[:subject] ||= []) << line.gsub( SUBJECT , '')
  68. :subject
  69. when FROM
  70. (@email[:from] ||= []) << line.gsub( FROM , '')
  71. :from
  72. when TO
  73. (@email[:to] ||= []) << line.gsub( TO , '')
  74. :to
  75. when CONTENT_TYPE
  76. (@email[:content_type] ||= []) << line.gsub( CONTENT_TYPE, '')
  77. :content_type
  78. else
  79. @email[prev] << line
  80. prev
  81. end
  82. end
  83.  
  84. puts @email.inspect
Add Comment
Please, Sign In to add comment