Skip to content

nice to have a keys function on headers... #21

Description

@coldnebo

While introspecting the mbox format, it would be nice to know what keys are available to query the headers. (to, from, etc are pretty obvious and standard, but other headers may be custom inserted by other clients, etc., so it's nice to have a handy dynamic reference of the keys available from a given message.)

here is the idea quick and dirty as a refinement:

class Mbox::Mail::Headers
  def keys
    @data.keys.map(&:to_sym).sort
  end
end

and an example of the output from iterating over messages from a gmail mbox export:

[1] pry(main)> m.headers.keys
=> [:authentication_results,
 :content_length,
 :content_type,
 :date,
 :delivered_to,
 :dkim_signature,
 :from,
 :in_reply_to,
 :message_id,
 :mime_version,
 :received,
 :received_spf,
 :references,
 :reply_to,
 :return_path,
 :subject,
 :to,
 :x_gm_thrid,
 :x_gmail_labels,
 :x_received,
 :x_yahoo_newman_id,
 :x_yahoo_newman_property,
 :x_ymail_osg]

Once I know the header keys, I can take advantage of the overloaded [] operator thus:

[2] pry(main)> m.headers[:date]
=> "Sun, 16 Aug 2015 13:08:26 +0000 (UTC)"

no time to add a pull request for this now, but maybe later.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions