Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sisimai::Lhost::DragonFly #293

Merged
merged 5 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/codecovio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ on:
push:
branches: ["5-stable"]
pull_request:
branches: ["5-stable"]
branches: ["*"]
jobs:
codecov:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository(CRuby)
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup CRuby
uses: ruby/setup-ruby@v1
with:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/rake-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches: ["5-stable"]
pull_request:
branches: ["5-stable"]
branches: ["*"]
jobs:
test-cruby:
name: rake test with CRuby ${{ matrix.cruby }}
Expand All @@ -15,6 +15,8 @@ jobs:
steps:
- name: Checkout the repository(CRuby)
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup CRuby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -38,7 +40,9 @@ jobs:
jruby: ["jruby-9.2", "jruby-9.4"]
steps:
- name: Checkout the repository(JRuby)
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup JRuby
uses: ruby/setup-ruby@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions lib/sisimai/lhost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def INDICATORS
def index
return %w[
Activehunter Amavis AmazonSES AmazonWorkMail Aol ApacheJames Barracuda Bigfoot Biglobe
Courier Domino EZweb EinsUndEins Exchange2003 Exchange2007 Exim FML Facebook GMX GSuite
GoogleGroups Gmail IMailServer InterScanMSS KDDI MXLogic MailFoundry MailMarshalSMTP
Courier Domino DragonFly EZweb EinsUndEins Exchange2003 Exchange2007 Exim FML Facebook GMX
GSuite GoogleGroups Gmail IMailServer InterScanMSS KDDI MXLogic MailFoundry MailMarshalSMTP
MailRu McAfee MessageLabs MessagingServer Notes Office365 OpenSMTPD Outlook Postfix
PowerMTA ReceivingSES SendGrid Sendmail SurfControl V5sendmail Verizon X1 X2 X3 X4 X5 X6
Yahoo Yandex Zoho MFILTER Qmail
Expand Down
113 changes: 113 additions & 0 deletions lib/sisimai/lhost/dragonfly.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module Sisimai::Lhost
# Sisimai::Lhost::DragonFly parses a bounce email which created by DMA: DragonFly Mail Agent.
# Methods in the module are called from only Sisimai::Message.
module DragonFly
class << self
require 'sisimai/lhost'
require 'sisimai/address'
require 'sisimai/smtp/command'

Indicators = Sisimai::Lhost.INDICATORS
Boundaries = ['Original message follows.', 'Message headers follow'].freeze
StartingOf = {
# https://github.com/corecode/dma/blob/ffad280aa40c242aa9a2cb9ca5b1b6e8efedd17e/mail.c#L84
message: ['This is the DragonFly Mail Agent '],
}.freeze
MessagesOf = {
'expired' => [
# https://github.com/corecode/dma/blob/master/dma.c#L370C1-L374C19
# dma.c:370| if (gettimeofday(&now, NULL) == 0 &&
# dma.c:371| (now.tv_sec - st.st_mtim.tv_sec > MAX_TIMEOUT)) {
# dma.c:372| snprintf(errmsg, sizeof(errmsg),
# dma.c:373| "Could not deliver for the last %d seconds. Giving up.",
# dma.c:374| MAX_TIMEOUT);
# dma.c:375| goto bounce;
# dma.c:376| }
'Could not deliver for the last ',
],
'hostunknown' => [
# net.c:663| snprintf(errmsg, sizeof(errmsg), "DNS lookup failure: host %s not found", host);
'DNS lookup failure: host ',
],
}.freeze

# Parse bounce messages from DMA: DragonFly Mail Agent
# @param [Hash] mhead Message headers of a bounce email
# @param [String] mbody Message body of a bounce email
# @return [Hash] Bounce data list and message/rfc822 part
# @return [Nil] it failed to parse or the arguments are missing
def inquire(mhead, mbody)
return nil unless mhead['subject'].start_with?('Mail delivery failed')
return nil unless mhead['received'].any? { |a| a.include?(' (DragonFly Mail Agent') }

dscontents = [Sisimai::Lhost.DELIVERYSTATUS]
emailparts = Sisimai::RFC5322.part(mbody, Boundaries)
bodyslices = emailparts[0].split("\n")
readcursor = 0 # (Integer) Points the current cursor position
recipients = 0 # (Integer) The number of 'Final-Recipient' header
v = nil

while e = bodyslices.shift do
# Read error messages and delivery status lines from the head of the email to the previous
# line of the beginning of the original message.
if readcursor == 0
# Beginning of the bounce message or delivery status part
readcursor |= Indicators[:deliverystatus] if e.start_with?(StartingOf[:message][0])
next
end
next if (readcursor & Indicators[:deliverystatus]) == 0
next if e.empty?

# This is the DragonFly Mail Agent v0.13 at df.example.jp.
#
# There was an error delivering your mail to <[email protected]>.
#
# email.example.jp [192.0.2.25] did not like our RCPT TO:
# 552 5.2.2 <[email protected]>: Recipient address rejected: Mailbox full
#
# Original message follows.
v = dscontents[-1]

if e.start_with?('There was an error delivering your mail to <')
# email.example.jp [192.0.2.25] did not like our RCPT TO:
# 552 5.2.2 <[email protected]>: Recipient address rejected: Mailbox full
if v['recipient']
# There are multiple recipient addresses in the message body.
dscontents << Sisimai::Lhost.DELIVERYSTATUS
v = dscontents[-1]

Check warning on line 77 in lib/sisimai/lhost/dragonfly.rb

View check run for this annotation

Codecov / codecov/patch

lib/sisimai/lhost/dragonfly.rb#L76-L77

Added lines #L76 - L77 were not covered by tests
end
v['recipient'] = Sisimai::Address.find(e, false)[0][:address]
recipients += 1
else
# Pick the error message
v['diagnosis'] ||= ''
v['diagnosis'] << ' ' << e

# Pick the remote hostname, and the SMTP command
# net.c:500| snprintf(errmsg, sizeof(errmsg), "%s [%s] did not like our %s:\n%s",
next unless e.include?(' did not like our ')
next if v['rhost']

p = e.split(' ', 3)
v['rhost'] = if p[0].include?('.') then p[0] else p[1] end
v['command'] = Sisimai::SMTP::Command.find(e) || ''
end
end
return nil unless recipients > 0

dscontents.each do |e|
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'])
MessagesOf.each_key do |r|
# Verify each regular expression of session errors
next unless MessagesOf[r].any? { |a| e['diagnosis'].include?(a) }
e['reason'] = r
break
end
end
return { 'ds' => dscontents, 'rfc822' => emailparts[1] }
end
def description; return 'DragonFly'; end
end
end
end

1 change: 1 addition & 0 deletions lib/sisimai/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class << self
'loop-alert' => ['Sisimai::Lhost::FML'],
'mail-delivery' => [
'Sisimai::Lhost::Exim',
'Sisimai::Lhost::DragonFly',
'Sisimai::Lhost::MailRu',
'Sisimai::Lhost::GMX',
'Sisimai::Lhost::EinsUndEins',
Expand Down
1 change: 1 addition & 0 deletions lib/sisimai/reason/norelaying.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class << self
'insecure mail relay',
'is not permitted to relay through this server without authentication',
'mail server requires authentication when attempting to send to a non-local e-mail address', # MailEnable
'no relaying',
'not a gateway',
'not allowed to relay through this machine',
'not an open relay, so get lost',
Expand Down
36 changes: 36 additions & 0 deletions set-of-emails/maildir/bsd/lhost-dragonfly-01.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Received: from MAILER-DAEMON
id e0720
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:02:02 +0900
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Tue, 11 Jun 2024 18:02:02 +0900

This is the DragonFly Mail Agent v0.13 at df.example.jp.

There was an error delivering your mail to <[email protected]>.

gmail-smtp-in.l.google.com [74.125.203.27] did not like our final DATA:
550-5.7.26 Unauthenticated email from example.jp is not accepted due to domain's
550-5.7.26 DMARC policy. Please contact the administrator of example.jp domain if
550-5.7.26 this was a legitimate mail. To learn about the DMARC initiative, go
550-5.7.26 to
550 5.7.26 https://support.google.com/mail/?p=DmarcRejection 98e67ed59e1d1-2c2d0e28189si6418580a91.13 - gsmtp

Message headers follow.

Received: from root (uid 0)
(envelope-from [email protected])
id e06d1
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:02:00 +0900
Subject: Nyaan 01
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 11 Jun 2024 18:02:00 +0900
Message-Id: <[email protected]>
From: <[email protected]>

Expand Down
32 changes: 32 additions & 0 deletions set-of-emails/maildir/bsd/lhost-dragonfly-02.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Received: from MAILER-DAEMON
id e0720
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:04:02 +0900
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Tue, 11 Jun 2024 18:04:02 +0900

This is the DragonFly Mail Agent v0.13 at df.example.jp.

There was an error delivering your mail to <[email protected]>.

outlook-com.olc.protection.outlook.com [52.101.42.17] did not like our final DATA:
550 5.7.509 Access denied, sending domain [DF.EXAMPLE.JP] does not pass DMARC verification and has a DMARC policy of reject. [TYCP286MB3363.JPNP286.PROD.OUTLOOK.COM 2024-06-11T09:04:02.679Z 08DC8850F12E1502] [MW4PR04CA0381.namprd04.prod.outlook.com 2024-06-11T09:04:02.743Z 08DC87B4931D8FD2] [CO1PEPF000066EC.namprd05.prod.outlook.com 2024-06-11T09:04:02.731Z 08DC89E7235090DB]

Message headers follow.

Received: from root (uid 0)
(envelope-from [email protected])
id e06d1
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:04:00 +0900
Subject: Nyaan 01
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 11 Jun 2024 18:04:00 +0900
Message-Id: <[email protected]>
From: <[email protected]>

32 changes: 32 additions & 0 deletions set-of-emails/maildir/bsd/lhost-dragonfly-03.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Received: from MAILER-DAEMON
id e0720
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:09:35 +0900
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Tue, 11 Jun 2024 18:09:35 +0900

This is the DragonFly Mail Agent v0.13 at df.example.jp.

There was an error delivering your mail to <[email protected]>.

mta5.am0.yahoodns.net [67.195.204.79] did not like our final DATA:
554 5.7.9 Message not accepted for policy reasons. See https://senders.yahooinc.com/error-codes

Message headers follow.

Received: from root (uid 0)
(envelope-from [email protected])
id e06d1
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:09:33 +0900
Subject: Nyaan 01
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 11 Jun 2024 18:09:33 +0900
Message-Id: <[email protected]>
From: <[email protected]>

31 changes: 31 additions & 0 deletions set-of-emails/maildir/bsd/lhost-dragonfly-04.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Received: from MAILER-DAEMON
id e0724
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:15:33 +0900
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Tue, 11 Jun 2024 18:15:33 +0900

This is the DragonFly Mail Agent v0.13 at df.example.jp.

There was an error delivering your mail to <[email protected]>.

DNS lookup failure: host cx.libsisimai.org not found

Message headers follow.

Received: from root (uid 0)
(envelope-from [email protected])
id e0722
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:15:33 +0900
Subject: Nyaan 01
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 11 Jun 2024 18:15:33 +0900
Message-Id: <[email protected]>
From: <[email protected]>

32 changes: 32 additions & 0 deletions set-of-emails/maildir/bsd/lhost-dragonfly-05.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Received: from MAILER-DAEMON
id e0724
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:17:34 +0900
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Tue, 11 Jun 2024 18:17:34 +0900

This is the DragonFly Mail Agent v0.13 at df.example.jp.

There was an error delivering your mail to <[email protected]>.

mail-inbound.libsisimai.net [192.0.2.25] did not like our RCPT TO:
550 5.7.26 <[email protected]>: Recipient address rejected: Multiple authentication checks failed

Message headers follow.

Received: from root (uid 0)
(envelope-from [email protected])
id e0722
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:17:33 +0900
Subject: Nyaan 01
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 11 Jun 2024 18:17:33 +0900
Message-Id: <[email protected]>
From: <[email protected]>

32 changes: 32 additions & 0 deletions set-of-emails/maildir/bsd/lhost-dragonfly-06.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Received: from MAILER-DAEMON
id e0726
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:21:33 +0900
X-Original-To: <[email protected]>
From: MAILER-DAEMON <>
To: [email protected]
Subject: Mail delivery failed
Message-Id: <[email protected]>
Date: Tue, 11 Jun 2024 18:21:33 +0900

This is the DragonFly Mail Agent v0.13 at df.example.jp.

There was an error delivering your mail to <[email protected]>.

mail-inbound.libsisimai.net [192.0.2.25] did not like our RCPT TO:
550 5.7.25 <[email protected]>: Recipient address rejected: Reverse DNS validation failed: See https://libsisimai.org/en/reason/#blocked

Message headers follow.

Received: from root (uid 0)
(envelope-from [email protected])
id e0724
by df.example.jp (DragonFly Mail Agent v0.13);
Tue, 11 Jun 2024 18:21:33 +0900
Subject: Nyaan 01
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 11 Jun 2024 18:21:33 +0900
Message-Id: <[email protected]>
From: <[email protected]>

Loading