Created
July 18, 2013 09:05
-
-
Save aminin/6027880 to your computer and use it in GitHub Desktop.
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
| # Годный метод для сериализации в yaml Mail::Message | |
| class Mail::Message | |
| # @return [String] | |
| def to_yaml | |
| hash = {} | |
| hash['headers'] = {} | |
| header.fields.each do |field| | |
| hash['headers'][field.name] = field.value | |
| end | |
| hash['delivery_handler'] = delivery_handler.to_s if delivery_handler | |
| hash['transport_encoding'] = transport_encoding.to_s | |
| special_variables = [:@header, :@delivery_handler, :@transport_encoding] | |
| if multipart? | |
| hash['multipart_body'] = [] | |
| body.parts.map { |part| hash['multipart_body'] << part.to_yaml } | |
| special_variables.push(:@body, :@text_part, :@html_part) | |
| end | |
| (instance_variables.map(&:to_sym) - special_variables).each do |var| | |
| hash[var.to_s] = instance_variable_get(var) | |
| end | |
| YAML.dump(hash) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment