Email:...derType(3pm)

πŸ“¦
version 0.814 Β· 2 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

okay so this is Email::FolderType, from the Perl user-contributed docs (Email::FolderType(3pm)) β€” it determines the type of a mail folder. that's it. that's the whole job. she's a specialist πŸ’…

🌸 VERSION 🌸

version 0.814 β€” we're on the modern timeline bestie ✨

πŸ¦‹ SYNOPSIS πŸ¦‹

  use Email::FolderType qw(folder_type);

  print folder_type "~/mymbox";     # prints 'Mbox'
  print folder_type "~/a_maildir/"; # prints 'Maildir'
  print folder_type "some_mh/.";    # prints 'MH'
  print folder_type "an_archive//"; # prints 'Ezmlm'

look at her go. four different folders, four instant answers, no drama πŸ‘‘

πŸ’– DESCRIPTION πŸ’–

she gives you a little utility subroutine that sniffs out what type of mail folder a given folder is. detection era. that's literally the vibe β€” you hand her a path, she tells you what she is 🌈

πŸŽ€ SUBROUTINES πŸŽ€

⭐ folder_type <path> ⭐

she auto-detects what type of mail folder your path is pointing at, and hands you back the name of that type. main character behaviour fr fr.

the way she does it: she's mostly clocking the suffix of the path you gave her.

  • / β†’ Maildir
  • /. β†’ MH
  • // β†’ Ezmlm

and if the suffix is giving nothing? then she checks for a known file structure. and if that doesn't work out either, she defaults to Mbox β€” BUT listen, this is important: if the Mbox matcher has been overridden, or the default has been changed (peep DEFAULT MATCHER down below πŸ‘‡), then she'll return undef instead. so don't be out here assuming, okay?

🧚 matchers 🧚

returns a list of all the matchers available to the system. the whole roster. the full squad 🫢

πŸ‘‘ DEFAULT MATCHER πŸ‘‘

currently the default matcher is Mbox, which means she is always checked last and always returns 1. she's the safety net. the fallback bestie.

so if you really wanna change that, you'd override Email::FolderType::Mbox::match and/or change the variable $Email::FolderType::DEFAULT to be something other than 'Mbox'. like this:

          use Email::FolderType;
          use Email::FolderType::Mbox;

          $Email::FolderType::DEFAULT = 'NewDefault';

      package Email::FolderType::Mbox;
      sub match { return (defined $_[0] && -f $_[0]) }

          package Email::FolderType::NewDefault;
          sub match { return (defined $_[0] && $_[0] =~ m!some crazy pattern!) }
          1;

that's the whole recipe. go off 😌

πŸ’… REGISTERING NEW TYPES πŸ’…

okay so tea time β˜• Email::FolderType briefly flirted with a rather clunky register_type method for registering new matchers β€” and in retrospect? that wasn't a great idea. we said what we said πŸ™ˆ

instead, in this version, we've reverted to a Module::Pluggable based system β€” meaning any classes sitting in the Email::FolderType:: namespace get interrogated to see if they have a c<match> method.

if they do, then she passes them the folder name. if the folder matches, the match function should return 1. for example...

      package Email::FolderType::GzippedMbox;

      sub match {
          my $folder = shift;
          return (-f $folder && $folder =~ /.gz$/);
      }

      1;

and honestly? these can even be defined inline ✨ like so:

      #!perl -w

      use strict;
      use Email::Folder;
      use Email::LocalDelivery;

      # copy all mail from an IMAP folder
      my $folder = Email::Folder->new('imap://example.com'); # read INBOX
      for ($folder->messages) {
          Email::LocalDelivery->deliver($_->as_string, 'local_mbox');
      }

      package Email::FolderType::IMAP;

      sub match {
          my $folder = shift;
          return $folder =~ m!^imap://!;
      }

      1;

so like β€” if there's demand for a compatability shim for the old register_type method, then sure, we can implement one. but really though? this is much better in the long run. trust πŸ’œ

πŸ“ AUTHOR πŸ“

Simon Wistow <simon@thegestalt.org> β€” icon, legend, the moment πŸ’–

This software is copyright (c) 2005 by Simon Wistow.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay, legally speaking 🫢


and that's the page bestie!! πŸŽ€ sign-off time: this was perl v5.36.0, dated 2023-07-19, and it lives under Email:...derType(3pm). no cap, go detect some folders πŸ’…βœ¨

πŸ“¦ where this page comes from