On Sun, Apr 07, 2024 at 09:23:07AM -0600, Charles Cazabon via Mutt-users wrote:
> Ебрашка <ebras...@riseup.net> wrote:
> > my mails have Message-ID: <zhjujjrae9inv...@example.com>.  Question, what
> > should I write in .muttrc to make my outgoing mails have the same beautiful
> > message-ID as Yandex mail? 
> 
> My first question would be, why do you care what the Message-ID: field
> contents look like?  Virtually no-one will ever look at it.

Yes, this here is fully true )))

> 
> > For example Message-Id: <43265...@example.com> consisting of random
> > digits and domain name
> 
> There's a good reason for that; it help to ensure uniqueness, which prevents
> problems with threading.  By limiting itself to only digits, Yandex's IDs are
> much more likely to collide.

Hm, not sure about that... Given that string is long enough,
random string which consists only out of digits can perhaps
compete with (much shorter) random string of alpha-numeric
characters - in terms of uniqueness probability?

> 
> If you absolutely must do this, have a look at the `message_id_format`
> variable.

Good hint ))) Attached is the example (perl) script, which can be used
as:

    set message_id_format = "$HOME/bin/mutt_message_id_format_filter '<%z@%f>'|"

This converts "left_part" provided by Mutt %z part of Message-ID
code (ZhJUjJRaE9InvXxm in your example above), into (much longer)
string of only digits (592493855977705398853375435077558962105453
for same example).

String of digits is 1:1 mapping of each byte code of every next
symbol in the source string, used in the triples with some
padding by spaces. Every tripple generates decimal number. All
numbers are put after each other into long result.

Code is certainly ugly but seems to work.

Cheers, Anton
#!/usr/bin/perl -w
use 5.010;
use strict;
my $val = $ARGV[0];

my $debug = 0;

if (! ($val =~ m/^<([^@]+)@([^>]+)>/)) {
        print $val; # message format is not recognized
        exit 0;
}

my $logfile = undef;
if ($debug) {
        my $log_fname = "/tmp/mutt_message_id_format_filter.log";
        open ($logfile, ">>", $log_fname)
                or die ("Cannot open [$log_fname] for write: $!");
}

my $left_part = $1;
my $host_n_domain = $2;

#abc
print $logfile "left_part = $left_part; host_n_domain = $host_n_domain\n"
        if ($debug);

my $new_left_part = "";
while (length($left_part)) {
        # extract 3 symbols, pad with blanks
        my $bytes = sprintf("%3.3s", substr($left_part, 0, 3));
        my $len = length($left_part);
        $left_part = substr($left_part, $len >= 3 ? 3 : $len);
        print $logfile " bytes = {" . $bytes . "}" if ($debug);
        my $num = 0;
        for my $i (0..2) {
                $num *= 256;
                $num += ord(substr($bytes, $i, 1));
        }
        print $logfile " num = {" . $num . "}\n" if ($debug);
        $new_left_part .= $num;
}

print $logfile "\n" if ($debug);
print $logfile "<$new_left_part@" . $host_n_domain . ">" if ($debug);
print "<$new_left_part@" . $host_n_domain . ">";
print $logfile "\n" if ($debug);

Reply via email to