Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/uri
File: mailto.rb
# frozen_string_literal: false
[0] Fix | Delete
# = uri/mailto.rb
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Akira Yamada <akira@ruby-lang.org>
[3] Fix | Delete
# License:: You can redistribute it and/or modify it under the same term as Ruby.
[4] Fix | Delete
# Revision:: $Id$
[5] Fix | Delete
#
[6] Fix | Delete
# See URI for general documentation
[7] Fix | Delete
#
[8] Fix | Delete
[9] Fix | Delete
require_relative 'generic'
[10] Fix | Delete
[11] Fix | Delete
module URI
[12] Fix | Delete
[13] Fix | Delete
#
[14] Fix | Delete
# RFC6068, the mailto URL scheme.
[15] Fix | Delete
#
[16] Fix | Delete
class MailTo < Generic
[17] Fix | Delete
include REGEXP
[18] Fix | Delete
[19] Fix | Delete
# A Default port of nil for URI::MailTo.
[20] Fix | Delete
DEFAULT_PORT = nil
[21] Fix | Delete
[22] Fix | Delete
# An Array of the available components for URI::MailTo.
[23] Fix | Delete
COMPONENT = [ :scheme, :to, :headers ].freeze
[24] Fix | Delete
[25] Fix | Delete
# :stopdoc:
[26] Fix | Delete
# "hname" and "hvalue" are encodings of an RFC 822 header name and
[27] Fix | Delete
# value, respectively. As with "to", all URL reserved characters must
[28] Fix | Delete
# be encoded.
[29] Fix | Delete
#
[30] Fix | Delete
# "#mailbox" is as specified in RFC 822 [RFC822]. This means that it
[31] Fix | Delete
# consists of zero or more comma-separated mail addresses, possibly
[32] Fix | Delete
# including "phrase" and "comment" components. Note that all URL
[33] Fix | Delete
# reserved characters in "to" must be encoded: in particular,
[34] Fix | Delete
# parentheses, commas, and the percent sign ("%"), which commonly occur
[35] Fix | Delete
# in the "mailbox" syntax.
[36] Fix | Delete
#
[37] Fix | Delete
# Within mailto URLs, the characters "?", "=", "&" are reserved.
[38] Fix | Delete
[39] Fix | Delete
# ; RFC 6068
[40] Fix | Delete
# hfields = "?" hfield *( "&" hfield )
[41] Fix | Delete
# hfield = hfname "=" hfvalue
[42] Fix | Delete
# hfname = *qchar
[43] Fix | Delete
# hfvalue = *qchar
[44] Fix | Delete
# qchar = unreserved / pct-encoded / some-delims
[45] Fix | Delete
# some-delims = "!" / "$" / "'" / "(" / ")" / "*"
[46] Fix | Delete
# / "+" / "," / ";" / ":" / "@"
[47] Fix | Delete
#
[48] Fix | Delete
# ; RFC3986
[49] Fix | Delete
# unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
[50] Fix | Delete
# pct-encoded = "%" HEXDIG HEXDIG
[51] Fix | Delete
HEADER_REGEXP = /\A(?<hfield>(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g<hfield>)*\z/
[52] Fix | Delete
# practical regexp for email address
[53] Fix | Delete
# https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
[54] Fix | Delete
EMAIL_REGEXP = /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/
[55] Fix | Delete
# :startdoc:
[56] Fix | Delete
[57] Fix | Delete
#
[58] Fix | Delete
# == Description
[59] Fix | Delete
#
[60] Fix | Delete
# Creates a new URI::MailTo object from components, with syntax checking.
[61] Fix | Delete
#
[62] Fix | Delete
# Components can be provided as an Array or Hash. If an Array is used,
[63] Fix | Delete
# the components must be supplied as <code>[to, headers]</code>.
[64] Fix | Delete
#
[65] Fix | Delete
# If a Hash is used, the keys are the component names preceded by colons.
[66] Fix | Delete
#
[67] Fix | Delete
# The headers can be supplied as a pre-encoded string, such as
[68] Fix | Delete
# <code>"subject=subscribe&cc=address"</code>, or as an Array of Arrays
[69] Fix | Delete
# like <code>[['subject', 'subscribe'], ['cc', 'address']]</code>.
[70] Fix | Delete
#
[71] Fix | Delete
# Examples:
[72] Fix | Delete
#
[73] Fix | Delete
# require 'uri'
[74] Fix | Delete
#
[75] Fix | Delete
# m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
[76] Fix | Delete
# m1.to_s # => "mailto:joe@example.com?subject=Ruby"
[77] Fix | Delete
#
[78] Fix | Delete
# m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
[79] Fix | Delete
# m2.to_s # => "mailto:john@example.com?Subject=Ruby&Cc=jack@example.com"
[80] Fix | Delete
#
[81] Fix | Delete
# m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
[82] Fix | Delete
# m3.to_s # => "mailto:listman@example.com?subject=subscribe"
[83] Fix | Delete
#
[84] Fix | Delete
def self.build(args)
[85] Fix | Delete
tmp = Util.make_components_hash(self, args)
[86] Fix | Delete
[87] Fix | Delete
case tmp[:to]
[88] Fix | Delete
when Array
[89] Fix | Delete
tmp[:opaque] = tmp[:to].join(',')
[90] Fix | Delete
when String
[91] Fix | Delete
tmp[:opaque] = tmp[:to].dup
[92] Fix | Delete
else
[93] Fix | Delete
tmp[:opaque] = ''
[94] Fix | Delete
end
[95] Fix | Delete
[96] Fix | Delete
if tmp[:headers]
[97] Fix | Delete
query =
[98] Fix | Delete
case tmp[:headers]
[99] Fix | Delete
when Array
[100] Fix | Delete
tmp[:headers].collect { |x|
[101] Fix | Delete
if x.kind_of?(Array)
[102] Fix | Delete
x[0] + '=' + x[1..-1].join
[103] Fix | Delete
else
[104] Fix | Delete
x.to_s
[105] Fix | Delete
end
[106] Fix | Delete
}.join('&')
[107] Fix | Delete
when Hash
[108] Fix | Delete
tmp[:headers].collect { |h,v|
[109] Fix | Delete
h + '=' + v
[110] Fix | Delete
}.join('&')
[111] Fix | Delete
else
[112] Fix | Delete
tmp[:headers].to_s
[113] Fix | Delete
end
[114] Fix | Delete
unless query.empty?
[115] Fix | Delete
tmp[:opaque] << '?' << query
[116] Fix | Delete
end
[117] Fix | Delete
end
[118] Fix | Delete
[119] Fix | Delete
super(tmp)
[120] Fix | Delete
end
[121] Fix | Delete
[122] Fix | Delete
#
[123] Fix | Delete
# == Description
[124] Fix | Delete
#
[125] Fix | Delete
# Creates a new URI::MailTo object from generic URL components with
[126] Fix | Delete
# no syntax checking.
[127] Fix | Delete
#
[128] Fix | Delete
# This method is usually called from URI::parse, which checks
[129] Fix | Delete
# the validity of each component.
[130] Fix | Delete
#
[131] Fix | Delete
def initialize(*arg)
[132] Fix | Delete
super(*arg)
[133] Fix | Delete
[134] Fix | Delete
@to = nil
[135] Fix | Delete
@headers = []
[136] Fix | Delete
[137] Fix | Delete
# The RFC3986 parser does not normally populate opaque
[138] Fix | Delete
@opaque = "?#{@query}" if @query && !@opaque
[139] Fix | Delete
[140] Fix | Delete
unless @opaque
[141] Fix | Delete
raise InvalidComponentError,
[142] Fix | Delete
"missing opaque part for mailto URL"
[143] Fix | Delete
end
[144] Fix | Delete
to, header = @opaque.split('?', 2)
[145] Fix | Delete
# allow semicolon as a addr-spec separator
[146] Fix | Delete
# http://support.microsoft.com/kb/820868
[147] Fix | Delete
unless /\A(?:[^@,;]+@[^@,;]+(?:\z|[,;]))*\z/ =~ to
[148] Fix | Delete
raise InvalidComponentError,
[149] Fix | Delete
"unrecognised opaque part for mailtoURL: #{@opaque}"
[150] Fix | Delete
end
[151] Fix | Delete
[152] Fix | Delete
if arg[10] # arg_check
[153] Fix | Delete
self.to = to
[154] Fix | Delete
self.headers = header
[155] Fix | Delete
else
[156] Fix | Delete
set_to(to)
[157] Fix | Delete
set_headers(header)
[158] Fix | Delete
end
[159] Fix | Delete
end
[160] Fix | Delete
[161] Fix | Delete
# The primary e-mail address of the URL, as a String.
[162] Fix | Delete
attr_reader :to
[163] Fix | Delete
[164] Fix | Delete
# E-mail headers set by the URL, as an Array of Arrays.
[165] Fix | Delete
attr_reader :headers
[166] Fix | Delete
[167] Fix | Delete
# Checks the to +v+ component.
[168] Fix | Delete
def check_to(v)
[169] Fix | Delete
return true unless v
[170] Fix | Delete
return true if v.size == 0
[171] Fix | Delete
[172] Fix | Delete
v.split(/[,;]/).each do |addr|
[173] Fix | Delete
# check url safety as path-rootless
[174] Fix | Delete
if /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*\z/ !~ addr
[175] Fix | Delete
raise InvalidComponentError,
[176] Fix | Delete
"an address in 'to' is invalid as URI #{addr.dump}"
[177] Fix | Delete
end
[178] Fix | Delete
[179] Fix | Delete
# check addr-spec
[180] Fix | Delete
# don't s/\+/ /g
[181] Fix | Delete
addr.gsub!(/%\h\h/, URI::TBLDECWWWCOMP_)
[182] Fix | Delete
if EMAIL_REGEXP !~ addr
[183] Fix | Delete
raise InvalidComponentError,
[184] Fix | Delete
"an address in 'to' is invalid as uri-escaped addr-spec #{addr.dump}"
[185] Fix | Delete
end
[186] Fix | Delete
end
[187] Fix | Delete
[188] Fix | Delete
true
[189] Fix | Delete
end
[190] Fix | Delete
private :check_to
[191] Fix | Delete
[192] Fix | Delete
# Private setter for to +v+.
[193] Fix | Delete
def set_to(v)
[194] Fix | Delete
@to = v
[195] Fix | Delete
end
[196] Fix | Delete
protected :set_to
[197] Fix | Delete
[198] Fix | Delete
# Setter for to +v+.
[199] Fix | Delete
def to=(v)
[200] Fix | Delete
check_to(v)
[201] Fix | Delete
set_to(v)
[202] Fix | Delete
v
[203] Fix | Delete
end
[204] Fix | Delete
[205] Fix | Delete
# Checks the headers +v+ component against either
[206] Fix | Delete
# * HEADER_REGEXP
[207] Fix | Delete
def check_headers(v)
[208] Fix | Delete
return true unless v
[209] Fix | Delete
return true if v.size == 0
[210] Fix | Delete
if HEADER_REGEXP !~ v
[211] Fix | Delete
raise InvalidComponentError,
[212] Fix | Delete
"bad component(expected opaque component): #{v}"
[213] Fix | Delete
end
[214] Fix | Delete
[215] Fix | Delete
true
[216] Fix | Delete
end
[217] Fix | Delete
private :check_headers
[218] Fix | Delete
[219] Fix | Delete
# Private setter for headers +v+.
[220] Fix | Delete
def set_headers(v)
[221] Fix | Delete
@headers = []
[222] Fix | Delete
if v
[223] Fix | Delete
v.split('&').each do |x|
[224] Fix | Delete
@headers << x.split(/=/, 2)
[225] Fix | Delete
end
[226] Fix | Delete
end
[227] Fix | Delete
end
[228] Fix | Delete
protected :set_headers
[229] Fix | Delete
[230] Fix | Delete
# Setter for headers +v+.
[231] Fix | Delete
def headers=(v)
[232] Fix | Delete
check_headers(v)
[233] Fix | Delete
set_headers(v)
[234] Fix | Delete
v
[235] Fix | Delete
end
[236] Fix | Delete
[237] Fix | Delete
# Constructs String from URI.
[238] Fix | Delete
def to_s
[239] Fix | Delete
@scheme + ':' +
[240] Fix | Delete
if @to
[241] Fix | Delete
@to
[242] Fix | Delete
else
[243] Fix | Delete
''
[244] Fix | Delete
end +
[245] Fix | Delete
if @headers.size > 0
[246] Fix | Delete
'?' + @headers.collect{|x| x.join('=')}.join('&')
[247] Fix | Delete
else
[248] Fix | Delete
''
[249] Fix | Delete
end +
[250] Fix | Delete
if @fragment
[251] Fix | Delete
'#' + @fragment
[252] Fix | Delete
else
[253] Fix | Delete
''
[254] Fix | Delete
end
[255] Fix | Delete
end
[256] Fix | Delete
[257] Fix | Delete
# Returns the RFC822 e-mail text equivalent of the URL, as a String.
[258] Fix | Delete
#
[259] Fix | Delete
# Example:
[260] Fix | Delete
#
[261] Fix | Delete
# require 'uri'
[262] Fix | Delete
#
[263] Fix | Delete
# uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
[264] Fix | Delete
# uri.to_mailtext
[265] Fix | Delete
# # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
[266] Fix | Delete
#
[267] Fix | Delete
def to_mailtext
[268] Fix | Delete
to = URI.decode_www_form_component(@to)
[269] Fix | Delete
head = ''
[270] Fix | Delete
body = ''
[271] Fix | Delete
@headers.each do |x|
[272] Fix | Delete
case x[0]
[273] Fix | Delete
when 'body'
[274] Fix | Delete
body = URI.decode_www_form_component(x[1])
[275] Fix | Delete
when 'to'
[276] Fix | Delete
to << ', ' + URI.decode_www_form_component(x[1])
[277] Fix | Delete
else
[278] Fix | Delete
head << URI.decode_www_form_component(x[0]).capitalize + ': ' +
[279] Fix | Delete
URI.decode_www_form_component(x[1]) + "\n"
[280] Fix | Delete
end
[281] Fix | Delete
end
[282] Fix | Delete
[283] Fix | Delete
"To: #{to}
[284] Fix | Delete
#{head}
[285] Fix | Delete
#{body}
[286] Fix | Delete
"
[287] Fix | Delete
end
[288] Fix | Delete
alias to_rfc822text to_mailtext
[289] Fix | Delete
end
[290] Fix | Delete
[291] Fix | Delete
@@schemes['MAILTO'] = MailTo
[292] Fix | Delete
end
[293] Fix | Delete
[294] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function