Net::S...ORWARD(3pm)
π Net::Server::Mail::ESMTP::XFORWARD β bestie, it's the XFORWARD module π
Okay so this is a page from the User Contributed Perl Documentation manual, and the star of the show is Net::Server::Mail::ESMTP::XFORWARD β a lil module that adds support for the XFORWARD command in Net::Server::Mail::ESMTP. π¦
β¨ NAME β¨
Net::Server::Mail::ESMTP::XFORWARD β a module to add support to the XFORWARD command in Net::Server::Mail::ESMTP. Periodt. π
πΈ SYNOPSIS πΈ
Like, here's the whole vibe in code form, no cap:
use Net::Server::Mail::ESMTP;
my @local_domains = qw(example.com example.org);
my $server = IO::Socket::INET->new( Listen => 1, LocalPort => 25 );
my $conn;
while($conn = $server->accept)
{
my $esmtp = Net::Server::Mail::ESMTP->new( socket => $conn );
# activate XFORWARD extension if remote client is localhost
$esmtp->register('Net::Server::Mail::ESMTP::XFORWARD')
if($server->get_property('peeraddr') =~ /^127/);
# adding some handlers
$esmtp->set_callback(RCPT => \&validate_recipient);
# adding XFORWARD handler
$esmtp->set_callback(XFORWARD => \&xforward);
$esmtp->process();
$conn->close();
}
sub xforward {
my $self = shift;
# Reject non IPV4 addresses
return 0 unless( $self->get_forwarded_address =~ /^\d+\.\d+\.\d+\.\d+$/ );
1;
}
sub validate_recipient
{
my($session, $recipient) = @_;
my $domain;
if($recipient =~ /\@(.*)>\s*$/)
{
$domain = $1;
}
if(not defined $domain)
{
return(0, 513, 'Syntax error.');
}
elsif(not(grep $domain eq $_, @local_domains) && $session->get_forwarded_addr != "10.1.1.1")
{
return(0, 554, "$recipient: Recipient address rejected: Relay access denied");
}
return(1);
}
π DESCRIPTION π
So here's the tea, bestie. When you're using a Net::Server::Mail::ESMTP script inside an MTA and not sitting out front on the Internet, stuff like the client IP address just... isn't accessible to the script. π And then when the script hands mail off to another instance of an smtpd daemon, it logs localhost as the incoming address. Which is, like, giving nothing. π
To fix this whole situation, some administrators use the XFORWARD command. This module gives you the ability to read and store XFORWARD information. Slay. β¨
π METHODS π
These methods return the values set by the upstream MTA without modifying them, so heads up: they can be set to undef or "[UNVAILABLE]". See Postfix documentation for more. π
get_forwarded_valuesβ returns a hash reference containing all values forwarded (keys in lower case). πget_forwarded_nameβ returns the up-stream hostname. The hostname may be a non-DNS hostname.get_forwarded_addressβ returns the up-stream network address. Address information is not enclosed with[]. The address may be a non-IP address.get_forwarded_sourceβ returnsLOCALorREMOTE.get_forwarded_heloβ returns the hostname that the up-stream host announced itself. It may be a non-DNS hostname.get_forwarded_protoβ returns the mail protocol for receiving mail from the up-stream host. This may be an SMTP or non-SMTP protocol name of up to 64 characters.
π₯ SEE ALSO π₯
Net::Server::Mail::ESMTP- <http://www.postfix.org/XFORWARD_README.html>
π AUTHOR π
Xavier Guimard, <x.guimard@free.fr> π«Ά
π COPYRIGHT AND LICENSE π
Copyright (C) 2006 by Xavier Guimard
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.4 or, at your option, any later version of Perl 5 you may have available.
And that's the whole page, bestie! This little icon was brought to you by perl v5.34.0, dated 2022-05-26, and honestly? It ate. π
β¨ Go forth and forward your XFORWARD values. π¦π
π¦ where this page comes from
- debian bookworm: libnet-server-mail-perl 0.28-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-server-mail-perl 0.28-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-server-mail-perl 0.28-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-server-mail-perl 0.28-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-server-mail-perl 0.28-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms