sisimai 4.22.1-java → 4.22.2-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sisimai might be problematic. Click here for more details.

Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +21 -0
  3. data/README-JA.md +2 -2
  4. data/README.md +2 -2
  5. data/lib/sisimai.rb +2 -3
  6. data/lib/sisimai/address.rb +20 -40
  7. data/lib/sisimai/arf.rb +4 -4
  8. data/lib/sisimai/bite.rb +1 -0
  9. data/lib/sisimai/bite/email.rb +3 -4
  10. data/lib/sisimai/bite/email/activehunter.rb +7 -7
  11. data/lib/sisimai/bite/email/amazonses.rb +14 -14
  12. data/lib/sisimai/bite/email/amazonworkmail.rb +7 -7
  13. data/lib/sisimai/bite/email/aol.rb +8 -8
  14. data/lib/sisimai/bite/email/apachejames.rb +7 -7
  15. data/lib/sisimai/bite/email/bigfoot.rb +7 -7
  16. data/lib/sisimai/bite/email/biglobe.rb +7 -7
  17. data/lib/sisimai/bite/email/courier.rb +9 -9
  18. data/lib/sisimai/bite/email/domino.rb +8 -8
  19. data/lib/sisimai/bite/email/einsundeins.rb +7 -7
  20. data/lib/sisimai/bite/email/exchange2003.rb +10 -10
  21. data/lib/sisimai/bite/email/exchange2007.rb +10 -10
  22. data/lib/sisimai/bite/email/exim.rb +18 -19
  23. data/lib/sisimai/bite/email/ezweb.rb +9 -11
  24. data/lib/sisimai/bite/email/facebook.rb +22 -23
  25. data/lib/sisimai/bite/email/gmx.rb +7 -7
  26. data/lib/sisimai/bite/email/google.rb +22 -25
  27. data/lib/sisimai/bite/email/gsuite.rb +17 -19
  28. data/lib/sisimai/bite/email/imailserver.rb +13 -13
  29. data/lib/sisimai/bite/email/interscanmss.rb +7 -7
  30. data/lib/sisimai/bite/email/kddi.rb +7 -7
  31. data/lib/sisimai/bite/email/mailfoundry.rb +6 -6
  32. data/lib/sisimai/bite/email/mailmarshalsmtp.rb +13 -13
  33. data/lib/sisimai/bite/email/mailru.rb +10 -10
  34. data/lib/sisimai/bite/email/mcafee.rb +7 -7
  35. data/lib/sisimai/bite/email/messagelabs.rb +9 -9
  36. data/lib/sisimai/bite/email/messagingserver.rb +8 -8
  37. data/lib/sisimai/bite/email/mfilter.rb +7 -7
  38. data/lib/sisimai/bite/email/mxlogic.rb +9 -9
  39. data/lib/sisimai/bite/email/notes.rb +12 -12
  40. data/lib/sisimai/bite/email/office365.rb +14 -15
  41. data/lib/sisimai/bite/email/opensmtpd.rb +7 -7
  42. data/lib/sisimai/bite/email/outlook.rb +9 -9
  43. data/lib/sisimai/bite/email/postfix.rb +13 -13
  44. data/lib/sisimai/bite/email/qmail.rb +9 -9
  45. data/lib/sisimai/bite/email/receivingses.rb +9 -9
  46. data/lib/sisimai/bite/email/sendgrid.rb +9 -9
  47. data/lib/sisimai/bite/email/sendmail.rb +7 -7
  48. data/lib/sisimai/bite/email/surfcontrol.rb +7 -7
  49. data/lib/sisimai/bite/email/userdefined.rb +7 -7
  50. data/lib/sisimai/bite/email/v5sendmail.rb +21 -22
  51. data/lib/sisimai/bite/email/verizon.rb +8 -8
  52. data/lib/sisimai/bite/email/x1.rb +6 -6
  53. data/lib/sisimai/bite/email/x2.rb +6 -6
  54. data/lib/sisimai/bite/email/x3.rb +6 -6
  55. data/lib/sisimai/bite/email/x4.rb +9 -9
  56. data/lib/sisimai/bite/email/x5.rb +6 -6
  57. data/lib/sisimai/bite/email/yahoo.rb +7 -7
  58. data/lib/sisimai/bite/email/yandex.rb +7 -7
  59. data/lib/sisimai/bite/email/zoho.rb +8 -8
  60. data/lib/sisimai/bite/json.rb +10 -11
  61. data/lib/sisimai/bite/json/amazonses.rb +11 -11
  62. data/lib/sisimai/bite/json/sendgrid.rb +67 -17
  63. data/lib/sisimai/data.rb +19 -21
  64. data/lib/sisimai/data/json.rb +3 -3
  65. data/lib/sisimai/data/yaml.rb +3 -3
  66. data/lib/sisimai/datetime.rb +18 -21
  67. data/lib/sisimai/mail.rb +1 -1
  68. data/lib/sisimai/mail/stdin.rb +2 -2
  69. data/lib/sisimai/mda.rb +4 -4
  70. data/lib/sisimai/message.rb +1 -1
  71. data/lib/sisimai/message/email.rb +32 -35
  72. data/lib/sisimai/message/json.rb +3 -3
  73. data/lib/sisimai/mime.rb +5 -6
  74. data/lib/sisimai/order/email.rb +11 -11
  75. data/lib/sisimai/order/json.rb +3 -3
  76. data/lib/sisimai/reason.rb +2 -2
  77. data/lib/sisimai/reason/userunknown.rb +4 -5
  78. data/lib/sisimai/rfc3464.rb +14 -16
  79. data/lib/sisimai/rfc3834.rb +5 -5
  80. data/lib/sisimai/rfc5322.rb +2 -2
  81. data/lib/sisimai/rhost.rb +6 -5
  82. data/lib/sisimai/rhost/exchangeonline.rb +1 -1
  83. data/lib/sisimai/rhost/godaddy.rb +87 -0
  84. data/lib/sisimai/rhost/googleapps.rb +1 -1
  85. data/lib/sisimai/smtp/error.rb +21 -27
  86. data/lib/sisimai/smtp/status.rb +2 -2
  87. data/lib/sisimai/string.rb +7 -7
  88. data/lib/sisimai/version.rb +1 -1
  89. data/set-of-emails/jsonobj/json-sendgrid-12.json +1 -0
  90. data/set-of-emails/jsonobj/json-sendgrid-13.json +1 -0
  91. data/set-of-emails/jsonobj/json-sendgrid-14.json +1 -0
  92. data/set-of-emails/jsonobj/json-sendgrid-15.json +1 -0
  93. data/set-of-emails/jsonobj/json-sendgrid-16.json +1 -0
  94. data/set-of-emails/jsonobj/json-sendgrid-17.json +1 -0
  95. data/set-of-emails/maildir/bsd/rhost-godaddy-01.eml +83 -0
  96. data/set-of-emails/maildir/bsd/rhost-godaddy-02.eml +69 -0
  97. metadata +11 -5
  98. data/lib/sisimai/ced.rb +0 -48
  99. data/lib/sisimai/msp.rb +0 -39
  100. data/lib/sisimai/mta.rb +0 -39
@@ -1,7 +1,7 @@
1
1
  module Sisimai::Bite::Email
2
+ # Sisimai::Bite::Email::Zoho parses a bounce email which created by Zoho Mail.
3
+ # Methods in the module are called from only Sisimai::Message.
2
4
  module Zoho
3
- # Sisimai::Bite::Email::Zoho parses a bounce email which created by Zoho Mail.
4
- # Methods in the module are called from only Sisimai::Message.
5
5
  class << self
6
6
  # Imported from p5-Sisimail/lib/Sisimai/Bite/Email/Zoho.pm
7
7
  require 'sisimai/bite/email'
@@ -14,15 +14,15 @@ module Sisimai::Bite::Email
14
14
  )
15
15
  }x,
16
16
  :'x-mailer' => %r/\AZoho Mail\z/,
17
- }
17
+ }.freeze
18
18
  Re1 = {
19
19
  :begin => %r/\AThis message was created automatically by mail delivery/,
20
20
  :rfc822 => %r/\AReceived:[ \t]*from mail[.]zoho[.]com/,
21
21
  :endof => %r/\A__END_OF_EMAIL_MESSAGE__\z/,
22
- }
22
+ }.freeze
23
23
  ReFailure = {
24
24
  expired: %r/Host not reachable/
25
- }
25
+ }.freeze
26
26
  Indicators = Sisimai::Bite::Email.INDICATORS
27
27
 
28
28
  def description; return 'Zoho Mail: https://www.zoho.com'; end
@@ -68,7 +68,7 @@ module Sisimai::Bite::Email
68
68
  end
69
69
  end
70
70
 
71
- if readcursor & Indicators[:'message-rfc822'] == 0
71
+ if (readcursor & Indicators[:'message-rfc822']).zero?
72
72
  # Beginning of the original message part
73
73
  if e =~ Re1[:rfc822]
74
74
  readcursor |= Indicators[:'message-rfc822']
@@ -87,7 +87,7 @@ module Sisimai::Bite::Email
87
87
 
88
88
  else
89
89
  # Before "message/rfc822"
90
- next if readcursor & Indicators[:deliverystatus] == 0
90
+ next if (readcursor & Indicators[:deliverystatus]).zero?
91
91
  next if e.empty?
92
92
 
93
93
  # This message was created automatically by mail delivery software.
@@ -113,7 +113,7 @@ module Sisimai::Bite::Email
113
113
  v['recipient'] = cv[1]
114
114
  v['diagnosis'] = cv[2]
115
115
 
116
- if v['diagnosis'] =~ /=\z/
116
+ if v['diagnosis'].end_with?('=')
117
117
  # Quoted printable
118
118
  v['diagnosis'] = v['diagnosis'].sub(/=\z/, '')
119
119
  qprintable = true
@@ -1,11 +1,10 @@
1
1
  module Sisimai
2
2
  module Bite
3
+ # Sisimai::Bite::JSON - Base class for Sisimai::Bite::JSON::*
3
4
  module JSON
4
- # Sisimai::Bite::JSON - Base class for Sisimai::Bite::JSON::*
5
5
  class << self
6
6
  # Imported from p5-Sisimail/lib/Sisimai/Bite/JSON.pm
7
7
  require 'sisimai/bite'
8
- require 'sisimai/rfc5322'
9
8
 
10
9
  def headerlist; return []; end
11
10
  def pattern; return []; end
@@ -17,18 +16,18 @@ module Sisimai
17
16
  end
18
17
 
19
18
  # Convert from JSON object to Sisimai::Message
20
- # @param [Hash] mhead Message header of a bounce email
21
- # @param [String] mbody Message body of a bounce email(JSON)
22
- # @return [Hash, Undef] Bounce data list and message/rfc822 part
23
- # or Undef if it failed to parse or the
24
- # arguments are missing
19
+ # @param [Hash] mhead Message header of a bounce email
20
+ # @param [String] mbody Message body of a bounce email(JSON)
21
+ # @return [Hash, Nil] Bounce data list and message/rfc822 part
22
+ # or nil if it failed to parse or the
23
+ # arguments are missing
25
24
  def scan; return nil; end
26
25
 
27
26
  # @abstract Adapt bounce object for Sisimai::Message format
28
- # @param [Hash] argvs bounce object returned from each email cloud
29
- # @return [Hash, Undef] Bounce data list and message/rfc822 part
30
- # or Undef if it failed to parse or the
31
- # arguments are missing
27
+ # @param [Hash] argvs bounce object returned from each email cloud
28
+ # @return [Hash, Nil] Bounce data list and message/rfc822 part
29
+ # or nil if it failed to parse or the
30
+ # arguments are missing
32
31
  def adapt; return nil; end
33
32
 
34
33
  end
@@ -21,7 +21,7 @@ module Sisimai::Bite::JSON
21
21
  :ContentRejected => '',
22
22
  :AttachmentRejected => '',
23
23
  },
24
- }
24
+ }.freeze
25
25
 
26
26
  def smtpagent; return Sisimai::Bite.smtpagent(self); end
27
27
  def description; return 'Amazon SES(JSON): http://aws.amazon.com/ses/'; end
@@ -98,8 +98,8 @@ module Sisimai::Bite::JSON
98
98
 
99
99
  # @abstract Adapt Amazon SES bounce object for Sisimai::Message format
100
100
  # @param [Hash] argvs bounce object(JSON) retrieved from Amazon SNS
101
- # @return [Hash, Nil] Bounce data list and message/rfc822 part
102
- # or Undef if it failed to parse or the
101
+ # @return [Hash, Nil] Bounce data list and message/rfc822 part or
102
+ # nil if it failed to parse or the
103
103
  # arguments are missing
104
104
  # @since v4.20.0
105
105
  def adapt(argvs)
@@ -119,8 +119,8 @@ module Sisimai::Bite::JSON
119
119
 
120
120
  if argvs['notificationType'] =~ /\A(?:Bounce|Complaint)\z/
121
121
  # { "notificationType":"Bounce", "bounce": { "bounceType":"Permanent",...
122
- o = argvs[ argvs['notificationType'].downcase ]
123
- r = o[ labeltable[ argvs['notificationType'].to_sym ] ] || []
122
+ o = argvs[argvs['notificationType'].downcase]
123
+ r = o[labeltable[argvs['notificationType'].to_sym]] || []
124
124
 
125
125
  r.each do |e|
126
126
  # 'bouncedRecipients' => [ { 'emailAddress' => 'bounce@si...' }, ... ]
@@ -161,11 +161,11 @@ module Sisimai::Bite::JSON
161
161
 
162
162
  if BounceType.key?(o['bounceType'].to_sym) &&
163
163
  BounceType[o['bounceType'].to_sym].key?(o['bounceSubType'].to_sym)
164
- # 'bounce' => {
165
- # 'bounceType' => 'Permanent',
166
- # 'bounceSubType' => 'General'
167
- # },
168
- v['reason'] = BounceType[o['bounceType'].to_sym][o['bounceSubType'].to_sym]
164
+ # 'bounce' => {
165
+ # 'bounceType' => 'Permanent',
166
+ # 'bounceSubType' => 'General'
167
+ # },
168
+ v['reason'] = BounceType[o['bounceType'].to_sym][o['bounceSubType'].to_sym]
169
169
  end
170
170
 
171
171
  else
@@ -235,7 +235,7 @@ module Sisimai::Bite::JSON
235
235
  argvs['mail']['headers'].each do |e|
236
236
  # 'headers' => [ { 'name' => 'From', 'value' => 'neko@nyaan.jp' }, ... ],
237
237
  next unless e['name'] =~ /\A(?:From|To|Subject|Message-ID|Date)\z/
238
- rfc822head[ e['name'].downcase ] = e['value']
238
+ rfc822head[e['name'].downcase] = e['value']
239
239
  end
240
240
  end
241
241
 
@@ -11,31 +11,89 @@ module Sisimai::Bite::JSON
11
11
 
12
12
  # @abstract Adapt SendGrid bounce object for Sisimai::Message format
13
13
  # @param [Hash] argvs bounce object(JSON) retrieved from SendGrid API
14
- # @return [Hash, Nil] Bounce data list and message/rfc822 part
15
- # or Undef if it failed to parse or the
14
+ # @return [Hash, Nil] Bounce data list and message/rfc822 part or
15
+ # nil if it failed to parse or the
16
16
  # arguments are missing
17
17
  # @since v4.20.0
18
18
  def adapt(argvs)
19
19
  return nil unless argvs.is_a? Hash
20
20
  return nil unless argvs.keys.size > 0
21
21
  return nil unless argvs.key?('email')
22
-
23
- dscontents = [Sisimai::Bite.DELIVERYSTATUS]
24
- rfc822head = {} # (Hash) Check flags for headers in RFC822 part
25
- recipients = 0 # (Integer) The number of 'Final-Recipient' header
26
- v = dscontents[-1]
22
+ return nil unless Sisimai::RFC5322.is_emailaddress(argvs['email'])
27
23
 
28
24
  require 'sisimai/string'
29
25
  require 'sisimai/address'
26
+ require 'sisimai/datetime'
27
+ require 'sisimai/smtp/reply'
28
+ require 'sisimai/smtp/status'
29
+
30
+ dscontents = nil
31
+ rfc822head = {}
32
+ v = nil
33
+
34
+ if argvs.key?('event')
35
+ # https://sendgrid.com/docs/API_Reference/Webhooks/event.html
36
+ # {
37
+ # 'tls' => 0,
38
+ # 'timestamp' => 1504555832,
39
+ # 'event' => 'bounce',
40
+ # 'email' => 'mailboxfull@example.jp',
41
+ # 'ip' => '192.0.2.22',
42
+ # 'sg_message_id' => '03_Wof6nRbqqzxRvLpZbfw.filter0017p3mdw1-11399-59ADB335-16.0',
43
+ # 'type' => 'blocked',
44
+ # 'sg_event_id' => 'S4wr46YHS0qr3BKhawTQjQ',
45
+ # 'reason' => '550 5.2.2 <mailboxfull@example.jp>... Mailbox Full ',
46
+ # 'smtp-id' => '<201709042010.v84KAQ5T032530@example.nyaan.jp>',
47
+ # 'status' => '5.2.2'
48
+ # },
49
+ return nil unless argvs['event'] =~ /\A(?:bounce|deferred|delivered|spamreport)\z/
50
+ dscontents = [Sisimai::Bite.DELIVERYSTATUS]
51
+ diagnostic = argvs['reason'] || ''
52
+ diagnostic = argvs['response'] || '' if diagnostic.empty?
53
+ timestamp0 = Sisimai::Time.parse(::Time.at(argvs['timestamp']).to_s)
54
+ v = dscontents[-1]
55
+
56
+ v['date'] = timestamp0.strftime("%a, %d %b %Y %T %z")
57
+ v['agent'] = self.smtpagent
58
+ v['lhost'] = argvs['ip'] || ''
59
+ v['status'] = argvs['status'] || nil
60
+ v['diagnosis'] = Sisimai::String.sweep(diagnostic)
61
+ v['recipient'] = argvs['email']
62
+
63
+ if argvs['event'] == 'delivered'
64
+ # "event": "delivered"
65
+ v['reason'] = 'delivered'
66
+ elsif argvs['event'] == 'spamreport'
67
+ # [
68
+ # {
69
+ # "email": "kijitora@example.com",
70
+ # "timestamp": 1504837383,
71
+ # "sg_message_id": "6_hrAeKvTDaB5ynBI2nbnQ.filter0002p3las1-27574-59B1FDA3-19.0",
72
+ # "sg_event_id": "o70uHqbMSXOaaoveMZIjjg",
73
+ # "event": "spamreport"
74
+ # }
75
+ # ]
76
+ v['reason'] = 'feedback'
77
+ v['feedbacktype'] = 'abuse'
78
+ end
79
+ v['status'] ||= Sisimai::SMTP::Status.find(v['diagnosis']) || ''
80
+ v['replycode'] ||= Sisimai::SMTP::Reply.find(v['diagnosis']) || ''
30
81
 
31
- if Sisimai::RFC5322.is_emailaddress(argvs['email'])
82
+ # Generate pseudo message/rfc822 part
83
+ rfc822head = {
84
+ 'from' => Sisimai::Address.undisclosed('s'),
85
+ 'message-id' => v['sg_message_id'],
86
+ }
87
+ else
32
88
  # {
33
89
  # "status": "4.0.0",
34
90
  # "created": "2011-09-16 22:02:19",
35
91
  # "reason": "Unable to resolve MX host sendgrid.ne",
36
92
  # "email": "esting@sendgrid.ne"
37
93
  # },
38
- recipients += 1
94
+ dscontents = [Sisimai::Bite.DELIVERYSTATUS]
95
+ v = dscontents[-1]
96
+
39
97
  v['recipient'] = argvs['email']
40
98
  v['date'] = argvs['created'] || ''
41
99
 
@@ -51,8 +109,6 @@ module Sisimai::Bite::JSON
51
109
  v['status'] = statuscode
52
110
  end
53
111
 
54
- require 'sisimai/smtp/reply'
55
- require 'sisimai/smtp/status'
56
112
  v['status'] ||= Sisimai::SMTP::Status.find(diagnostic)
57
113
  v['replycode'] ||= Sisimai::SMTP::Reply.find(diagnostic)
58
114
  v['diagnosis'] = argvs['reason'] || ''
@@ -60,16 +116,10 @@ module Sisimai::Bite::JSON
60
116
 
61
117
  # Generate pseudo message/rfc822 part
62
118
  rfc822head = {
63
- 'to' => argvs['email'],
64
119
  'from' => Sisimai::Address.undisclosed('s'),
65
120
  'date' => v['date'],
66
121
  }
67
- else
68
- # The value of $argvs->{'email'} does not seems to an email address
69
- return nil
70
122
  end
71
-
72
- return nil if recipients.zero?
73
123
  return { 'ds' => dscontents, 'rfc822' => rfc822head }
74
124
  end
75
125
 
@@ -47,22 +47,20 @@ module Sisimai
47
47
  AddrHeader = {
48
48
  addresser: RFC822Head[:addresser],
49
49
  recipient: RFC822Head[:recipient],
50
- }
50
+ }.freeze
51
51
  ActionList = %r/\A(?:failed|delayed|delivered|relayed|expanded)\z/
52
52
  ActionHead = {
53
53
  %r/\Afailure\z/ => 'failed',
54
54
  %r/\Aexpired\z/ => 'delayed',
55
- }
55
+ }.freeze
56
56
 
57
57
  # Constructor of Sisimai::Data
58
58
  # @param [Hash] argvs Data
59
59
  # @return [Sisimai::Data] Structured email data
60
60
  def initialize(argvs)
61
- thing = {}
62
-
63
61
  # Create email address object
64
62
  as = Sisimai::Address.make(argvs['addresser'])
65
- ar = Sisimai::Address.make({ address: argvs['recipient'] })
63
+ ar = Sisimai::Address.make(address: argvs['recipient'])
66
64
 
67
65
  return nil unless as.is_a? Sisimai::Address
68
66
  return nil unless ar.is_a? Sisimai::Address
@@ -216,7 +214,7 @@ module Sisimai
216
214
  end
217
215
 
218
216
  if datestring
219
- # Get the value of timezone offset from $datestring
217
+ # Get the value of timezone offset from datestring
220
218
  if cv = datestring.match(/\A(.+)[ ]+([-+]\d{4})\z/)
221
219
  # Wed, 26 Feb 2014 06:05:48 -0500
222
220
  datestring = cv[1]
@@ -361,13 +359,13 @@ module Sisimai
361
359
  textasargv = textasargv.gsub(/\A[ ]/, '')
362
360
  softorhard = Sisimai::SMTP::Error.soft_or_hard(o.reason, textasargv)
363
361
 
364
- if softorhard.size > 0
365
- # Returned value is "soft" or "hard"
366
- o.softbounce = (softorhard == 'soft') ? 1 : 0
367
- else
368
- # Returned value is an empty string
369
- o.softbounce = (-1)
370
- end
362
+ o.softbounce = if softorhard.size > 0
363
+ # Returned value is "soft" or "hard"
364
+ (softorhard == 'soft') ? 1 : 0
365
+ else
366
+ # Returned value is an empty string
367
+ -1
368
+ end
371
369
  end
372
370
 
373
371
  if o.deliverystatus.empty?
@@ -387,13 +385,13 @@ module Sisimai
387
385
  # set the value of "softbounce" again when the value is -1
388
386
  softorhard = Sisimai::SMTP::Error.soft_or_hard(o.reason, pseudocode)
389
387
 
390
- if softorhard.size > 0
391
- # Returned value is "soft" or "hard"
392
- o.softbounce = softorhard == 'soft' ? 1 : 0
393
- else
394
- # Returned value is an empty string
395
- o.softbounce = -1
396
- end
388
+ o.softbounce = if softorhard.size > 0
389
+ # Returned value is "soft" or "hard"
390
+ softorhard == 'soft' ? 1 : 0
391
+ else
392
+ # Returned value is an empty string
393
+ -1
394
+ end
397
395
  end
398
396
  end
399
397
  end
@@ -427,7 +425,7 @@ module Sisimai
427
425
 
428
426
  # Data dumper
429
427
  # @param [String] type Data format: json, yaml
430
- # @return [String, Undef] Dumped data or Undef if the value of first
428
+ # @return [String, Nil] Dumped data or nil if the value of the first
431
429
  # argument is neither "json" nor "yaml"
432
430
  def dump(type = 'json')
433
431
  return nil unless %w|json yaml|.index(type)
@@ -6,9 +6,9 @@ module Sisimai
6
6
  # Imported from p5-Sisimail/lib/Sisimai/Data/JSON.pm
7
7
  class << self
8
8
  # Data dumper(JSON)
9
- # @param [Sisimai::Data] argvs Object
10
- # @return [String, Nil] Dumped data or Undef if the argument
11
- # is missing
9
+ # @param [Sisimai::Data] argvs Object
10
+ # @return [String, Nil] Dumped data or nil if the argument
11
+ # is missing
12
12
  def dump(argvs)
13
13
  return nil unless argvs
14
14
  return nil unless argvs.is_a? Sisimai::Data
@@ -8,9 +8,9 @@ module Sisimai
8
8
  require 'yaml'
9
9
 
10
10
  # Data dumper(YAML)
11
- # @param [Sisimai::Data] argvs Object
12
- # @return [String, Undef] Dumped data or Undef if the argument
13
- # is missing
11
+ # @param [Sisimai::Data] argvs Object
12
+ # @return [String, Nil] Dumped data or nil if the argument
13
+ # is missing
14
14
  def dump(argvs)
15
15
  return nil unless argvs
16
16
  return nil unless argvs.is_a? Sisimai::Data
@@ -25,23 +25,23 @@ module Sisimai
25
25
  b: 86.4, # Beat, Swatch internet time: 1000b = 1d
26
26
  m: 60, # Minute,
27
27
  s: 1, # Second
28
- }
28
+ }.freeze
29
29
 
30
30
  MathematicalConstant = {
31
31
  e: CONST_E,
32
32
  p: CONST_P,
33
33
  g: CONST_E**CONST_P,
34
- }
34
+ }.freeze
35
35
 
36
36
  MonthName = {
37
37
  full: %w|January February March April May June July August September October November December|,
38
38
  abbr: %w|Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec|,
39
- }
39
+ }.freeze
40
40
 
41
41
  DayOfWeek = {
42
42
  full: %w|Sunday Monday Tuesday Wednesday Thursday Friday Saturday|,
43
- abbr: %w|Sun Mon Tue Wed Thu Fri Sat |,
44
- }
43
+ abbr: %w|Sun Mon Tue Wed Thu Fri Sat|,
44
+ }.freeze
45
45
 
46
46
  HourName = {
47
47
  full: [
@@ -49,7 +49,7 @@ module Sisimai
49
49
  'Noon', 13, 14, 15, 16, 17, 'Evening', 19, 20, 21, 22, 23,
50
50
  ],
51
51
  abbr: [0..23],
52
- }
52
+ }.freeze
53
53
 
54
54
  TimeZoneAbbr = {
55
55
  # http://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
@@ -178,7 +178,7 @@ module Sisimai
178
178
  # WET: '-0000', # Western European Time UTC
179
179
  # YAKT: '+0900', # Yakutsk Time UTC+09:00
180
180
  # YEKT: '+0500', # Yekaterinburg Time UTC+05:00
181
- }
181
+ }.freeze
182
182
 
183
183
  # Convert to second
184
184
  # @param [String] argv1 Digit and a unit of time
@@ -334,7 +334,7 @@ module Sisimai
334
334
  end
335
335
 
336
336
  elsif cr = p.match(/\A([0-2]\d):([0-5]\d):([0-5]\d)\z/) ||
337
- cr = p.match(/\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/)
337
+ p.match(/\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/)
338
338
  # Time; 12:34:56, 03:14:15, ...
339
339
  # Arrival-Date: 2014-03-26 00-01-19
340
340
 
@@ -379,10 +379,7 @@ module Sisimai
379
379
  # ISO 8601; 2000-04-29T01:23:45
380
380
  v[:Y] = cr[1].to_i
381
381
  v[:M] = MonthName[:abbr][cr[2].to_i - 1]
382
-
383
- if cr[3].to_i < 32
384
- v[:d] = cr[3].to_i
385
- end
382
+ v[:d] = cr[3].to_i if cr[3].to_i < 32
386
383
 
387
384
  if cr[4].to_i < 24 && cr[5].to_i < 60 && cr[6].to_i < 60
388
385
  v[:T] = sprintf('%02d:%02d:%02d', cr[4], cr[5], cr[6])
@@ -417,13 +414,13 @@ module Sisimai
417
414
  # Adjust 2-digit Year
418
415
  if altervalue[:Y] && !v[:Y]
419
416
  # Check alternative value(Year)
420
- if altervalue[:Y].to_i >= 82
421
- # SMTP was born in 1982
422
- v[:Y] ||= 1900 + altervalue[:Y].to_i
423
- else
424
- # 20XX
425
- v[:Y] ||= 2000 + altervalue[:Y].to_i
426
- end
417
+ v[:Y] ||= if altervalue[:Y].to_i >= 82
418
+ # SMTP was born in 1982
419
+ 1900 + altervalue[:Y].to_i
420
+ else
421
+ # 20XX
422
+ 2000 + altervalue[:Y].to_i
423
+ end
427
424
  end
428
425
 
429
426
  # Check each piece
@@ -445,7 +442,7 @@ module Sisimai
445
442
 
446
443
  # Abbreviation -> Tiemzone
447
444
  # @param [String] argv1 Abbr. e.g.) JST, GMT, PDT
448
- # @return [String, Undef] +0900, +0000, -0600 or Undef if the argument is
445
+ # @return [String, Nil] +0900, +0000, -0600 or nil if the argument is
449
446
  # invalid format or not supported abbreviation
450
447
  # @example Get the timezone string of "JST"
451
448
  # abbr2tz('JST') #=> '+0900'
@@ -456,7 +453,7 @@ module Sisimai
456
453
 
457
454
  # Convert to second
458
455
  # @param [String] argv1 Timezone string e.g) +0900
459
- # @return [Integer,Undef] n: seconds or Undef it the argument is invalid
456
+ # @return [Integer, Nil] n: seconds or nil it the argument is invalid
460
457
  # format string
461
458
  # @see second2tz
462
459
  # @example Convert '+0900' to seconds