NetSDS...:SMTPD(3pm)

πŸ“¦
version 1.301 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ‘‘ NAME πŸ‘‘

NetSDS::App::SMTPD β€” it's giving SMTP server app class, bestie. That's the whole name, that's the whole vibe. ✨


πŸŽ€ SYNOPSIS πŸŽ€

use NetSDS::App::SMTPD

That's it. One line. Iconic behavior fr fr. πŸ’…


πŸ’– PACKAGES πŸ’–

Okay so this page is actually a little family reunion β€” there's a base package and a few friends under it, so let's go one by one, no skipping, we do NOT skip around here. 🫢

πŸ¦‹ NetSDS::App::SMTPD::Socket

Needs for work with socket, periodt. This module is a parent for NetSDS::App::SMTPD and NetSDS::App::SMTPD::Client, and a child of a NetSDS::APP. So it's giving both mom and daughter energy, which is honestly so real of it. πŸ’€

ITEMS

  • create_socket β€” Creating a simple socket which could be transformed into a listening in NetSDS::App::SMTPD and could be used in NetSDS::App::SMTPD::Client for accept connection. Lowkey the origin story of every connection. 🌱
  • can_read β€” This method uses for making a timeout before connections to the server: if there is no connections to accept, program would be just waiting in select while the connection appeared. So basically it's the "anyone? anyone? Bueller?" method. πŸ™ˆ
  • close_socket β€” Close socket. Short. Sweet. Slays. πŸ’…

🌸 NetSDS::App::SMTPD::Client

Provides the smtp protocol bu using Net::Server::Mail::SMTP. (Yes, "bu" β€” that's what the original says and we respect the original's choices. 😭)

Had attributes, bestie, listen up:

  • smtp β€” an object of Net::Server::Mail::SMTP
  • ip β€” ip of the remote host
  • headers β€” ref hash with headers of a message
  • msg β€” a body of a message

ITEMS

  • set_callback and process β€” All that subs do β€” its only call the methods of a Net::Server::Mail::SMTP with the same name. They're not doing extra, they're not doing less. They're middlemen and they're at peace with it. 🧚
  • get_mail β€” In this sub we parse message and set headers of the object and message body. This sub is call as a callback on event DATA. So when DATA shows up, this one gets to work. πŸ”₯
  • get_header and get_msg β€” Get methods that make you access to a header of a msg and message body. Example: $client->get_header('FROM') or $client->get_header('to'); β€” note that casing is doing whatever it wants in there and we simply pass that along. πŸ‘‘

πŸ’œ NetSDS::App::SMTPD

This module init a smtp-server. That's the whole job description and honestly? Respect the brevity.

ITEMS

  • create_socket β€” Init a listening socket by creating a simple socket Super::create_socket and make it listening. ✨
  • data β€” Takes β€” a message that has been received, parses them and prepare the structure of headers, body for next actions. It's the prep cook of this whole operation. πŸ“
  • accept β€” Waiting for an smtp connection and that accept it. Main character energy: it just stands there until someone shows up. πŸŽ€
  • data β€” (yep, data shows up in this list twice in the original β€” we do not edit, we do not merge, we simply observe and honor it πŸ’€)
  • process β€” (listed here with no description in the original, so no description it is. We're nothing if not faithful. 🫢)

🌈 EXAMPLE 🌈

Okay this is the part you actually came for, so here it is, exactly as written:

#!/usr/bin/env perl

use strict;
use warnings;

Receiver->run(
        infinite  => 1,
        debug     => 1,
        verbose   => 1,
        conf_file => '../conf/mts-receiver.conf',
);

1;

package Receiver;
use base 'NetSDS::App::SMTPD';

sub process {
        my $self = shift;
        my $client = $self->SUPER::process;

        #do something with msg;
        my $from = $client->get_header('from');
        my $msg = $client->get_msg;

        .....

        return $self;
};

or you could reinit process like this:

sub process {
        my $self = shift;
        my $client = $self->accept;

        return unless $client;
        $client->process;

        #do something
        ......
        $client->close;
        return $self;
};

See how the first one rides on SUPER::process and the second one grabs accept directly, checks return unless $client;, runs $client->process;, does something, then $client->close;? Two paths, both valid, both cute. πŸ¦‹

Heads up bestie: that ..... and that ...... are literally in the original. They are not me being lazy. Do not @ me. πŸ’…

πŸ’œ AUTHOR πŸ’œ

Yana Kornienko <yana@netstyle.com.ua> β€” thank you for your service, queen. πŸ‘‘


And that's the whole page, no cap. This little gem is from the User Contributed Perl Documentation, it's perl v5.32.1, dated 2021-12-26, and the page itself answers to the name NetSDS...:SMTPD(3pm). Love that for it. Go build something, bestie β€” you got this. πŸ’–βœ¨πŸŽ€πŸ¦‹