Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Generating Message_id email headers

by afoken (Abbot)
on May 19, 2017 at 18:25 UTC ( #1190665=note: print w/replies, xml ) Need Help??


in reply to Re: Generating Message_id email headers
in thread Generating Message_id email headers

No need to use UUIDs. Message IDs just have to be unique. Combining fully qualified hostname, timestamp (even if only with second resolution), process ID, and a random number should be sufficient.

Let's look at some real-world data:

Running grep -h -i --perl '^Message-ID' * in my inbox (in imapdir format, i.e. one file per mail, no special encoding) returns these (duplicate formats mostly removed, some names and numbers X-ed out):

Message-ID: <24746fb3-8c48-1412-5e8b-bfdb6735b214@foken.de> Message-ID: <re-pLd1axQBsDx57b7oqugsM5Ofj-2078PSB9-205B0OGX-ZD2Q32@new +sletter.lieferando.de> Message-ID: <8f31036b-d534-2c6d-fde4-ec03aa28b355@gmx.de> Message-ID: <20170102172202.74342.42518@pde-live-app5> Message-ID: <y-b-vryxQaigSHMT84qhHg@ismtpd0001p1lon1.sendgrid.net> Message-ID: <fe996f03-5674-4184-321a-cc1a4a1e83b5@cXXXXXd.de> Message-ID: <53149ca4-dc49-1a83-2878-d5ac005bee1d@foken.de> Message-ID: <CAJ5Xak6KKnmo-4HxLeNg1aGyRTkmYGdPM6ph=tfCxpg0j_s9gw@mail. +gmail.com> Message-Id: <20170105030539.A68907C4A0@srv162.bader.de> Message-ID: <1bd0c853-751c-d823-8e3b-147d588c296f@foken.de> Message-ID: <286043904.95.XXXX7354XXXX.JavaMail.ggbader1@gtunxlvh00658 +.server.arvato-systems.de> Message-ID: <m0b8cdt0E34Nqdu.RZmta@smtp.rzone.de> Message-ID: <20170122_102124_047518.vroom@perlmonks.org> Message-ID: <1555628483.587.14XXX486XXX.JavaMail.amsap21@degtams2> Message-ID: <01020159f3ff5810-5fXXXXX-215f-4b49-b4dd-3a5eafXXXXX-00000 +0@eu-west-1.amazonses.com> Message-ID: <5890EE9C.2000604@foken.de> Message-ID: <E5-gkhm1jm5-nr113/XX/XXXXX-18f0a3bd@wrk-1505.artegic.net> Message-Id: <20170213123704.2723380261@web3.po23.spacenet.de> Message-ID: <17997d6269704c37af1f86b072d23dc6@pollin-exchange.pollin-d +e.local> Message-ID: <1043052060.59.1488540102150.JavaMail.lithium@sjc1papp91.s +j.lithium.com> Message-ID: <ic974ihadr6t5xjxk1mstfvr.1489696175625@email.android.com> Message-Id: <15b576a93ed-3749-7fc5@webstg-a10.mail.aol.com> Message-Id: <E1d2qiD-0008PH-8Y@enterprise.foken.wtm> Message-ID: <D5261642.F9DB%kontakt@juXXXXXka.de> Message-ID: <001201d2c27b$206d5dd0$61481970$@gmx.de> Message-Id: <20170503161455.17E47482CA@dvm034.uptrade.de> Message-ID: <5.5e9852b0cf96ca350167@NY-WEB01> Message-ID: <8111f0b0-7d50-4564-b756-0a872e7361a5@chd1b02c-4776>

Yes, there are UUIDs, almost always combined with a hostname. But there is also other more or less hashed data. Sometimes, its a plain timestamp (20170503161455 is obviously 2017-05-03 16:14:55) or a unix timestamp (1488540102150 is milliseconds since 1970 for 2017-03-03 11:21:42 UTC). kontakt@juXXXXXka.de is the address I wrote to, it was used as part of the message ID of the reply. And similar to boundary strings, you can find fragments of domain names, hostnames and user agent names in the message IDs, as well as bas64 and hex encoded "junk", and some seemingly random printable characters.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: Generating Message_id email headers
by astrobal (Acolyte) on May 21, 2017 at 13:59 UTC

    Well, its turns out to be quite easy in the end.

    There is no required format for the Message Id, so it can be pretty much anything you like, but it does have to be unique. However, as has been noted, the general accepted format of a Message Id is $a(separator)$b@domain_name, where $a is essentially some form of timestamp and $b is some form of random element. So, here is what I created. The timestamp is generated from localtime and a random number from rand().

    my @dayofweek = (qw(Sun Mon Tue Wed Thu Fri Sat)); my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)) +; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday, $isdst) = localtime( +); $year += 1900; my $ran_num = int(rand(100000)); #This is a 5 figure random number whi +ch ensures the MID is really, really unique! # Create a Message Id my $MID = sprintf("<%04d:%02d:%s:%s-%02d:%02d:%02d-%05d\@company_name. +com>", $year, $mday, $monthnames[$mon], $dayofweek[$wday], $hour, $min, $sec, + $ran_num);

    And this is an example of what $MID looks like:

    <2017:21:May:Sun-07:36:11-57049@company_name.com>

    spamassassin seemed to think this was ok and so lowered the spam score accordingly, so helping prevent my script-generated emails ending up in the spam folder.

    Many thanks to those who replied. I appreciated your comments and suggestions.

    Geoffrey

Re^3: Generating Message_id email headers
by tobyink (Abbot) on May 19, 2017 at 20:29 UTC

    Never said it needed to be a UUID. Using a UUID is just a very easy way to get an almost-certainly unique string.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190665]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-07-20 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (304 votes). Check out past polls.