Module: Mailmate::MidUrl
- Defined in:
- lib/mailmate/mid_url.rb
Overview
Build a MailMate ‘mid:` URL from a Message-ID. MailMate registers the `mid:` scheme (RFC 2392) and resolves it to a specific message. The angle brackets that bracket the Message-ID in headers must be percent-encoded.
Class Method Summary collapse
-
.for(message_id) ⇒ Object
Returns ‘mid:%3C<message-id>%3E`.
Class Method Details
.for(message_id) ⇒ Object
Returns ‘mid:%3C<message-id>%3E`. Accepts the Message-ID with or without surrounding angle brackets — strips them either way before encoding. URL-encodes characters that would break the URL parser, notably `[` and `]` (which appear in Message-IDs containing IPv4 literals, e.g. `<id@>`). Other URL-reserved characters (`@`, `.`, `-`, `_`, etc.) are preserved — MailMate’s parser accepts them as-is.
16 17 18 19 20 21 |
# File 'lib/mailmate/mid_url.rb', line 16 def self.for() raise ArgumentError, "Message-ID required" if .nil? || .to_s.empty? id = .to_s.sub(/\A</, "").sub(/>\z/, "") encoded = id.gsub(/[\[\]<>\s]/) { |c| "%%%02X" % c.ord } "mid:%3C#{encoded}%3E" end |