From: rhys@meteor.brisnet.org.au (Rhys Weatherley)
Newsgroups: comp.bbs.waffle
Subject: Re: Utility to Explode Digests?
Date: Sat, 10 Oct 92 20:26:52 +1000
Reply-To: rhys%meteor@bunyip.cc.uq.oz.au
Organization: meteor - Home of Helldiver and UW/PC

In <1b2f3bINNrgc@golem.wcc.govt.nz> cain_p@kosmos.wcc.govt.nz writes:
>In article <iZu0RB1w165w@cybrspc.UUCP>, roy%cybrspc@cs.umn.edu (Roy M. Silvernail) writes:
>>Sure, I can use a sequence number.  In fact, I might just do that, for a
>>quick fix.

>You could get the unique string by using the C call that returns the
>number of seconds since 1970 as a long, then just use a bit move to
>turn each set of 4 (or 5?) bits into printable characters.. like
>how uu/xxencode work.  That's probably how waffle does it.  But if

OK.  I've been having some discussions in mail with someone about generating
Message-Id's, and this thread just came up, so I'll post this code fragment
from Helldiver Send which I use to generate them.  It uses a number of
global variables which are initialised by the startup code in Helldiver
Send:

	CurrentDateTime		value from calling "time(0)".
	TickValue		"biostime(0,0L) % 100".
	MessageNumber		a number that starts at 1 and increases
				for every Message-Id generated by the
				same call to Helldiver Send, so I can send
				more than one message at once.
	MailerIdent		a small string to insert into the id to
				indicate the software.  e.g. "w165w", or
				"h106h", etc.
	HostName		full domain name of the host.

The algorithm gives a pretty compact Message-Id, and should generate id's
that are unique enough.  If two Message-Id's are generated by separate
processes in the same 18.2'th of a second, then you will get a repetition,
but what's the likelihood of that?  If you are using this on something
other than MS-DOS, you just need to find a rapidly changing value somewhere
for TickValue.

You can do whatever you want with this code.  Oh, and if anyone knows of
a problem with any software of generating Message-Id's in this way, I'd
like to know.

Cheers,

Rhys.

----cut-here----
//
// Define the characters of the base64 encoding scheme.  These are
// used to encode Message-Id's.  Note: '/' in standard base64 has
// been replaced by '-' to avoid bad Message-Ids.
//
static	char	*base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
			       "abcdefghijklmnopqrstuvwxyz"
			       "0123456789+-";

//
// Output a base64 string representation of a long number.
// "numchs" gives the maximum number of characters to output.
//
static	int	OutputBase64Number (FILE *file,unsigned long value,int numchs)
{
  while (numchs-- > 0)
    {
      if (fputc (base64chars[(int)(value & 0x3F)],file) == EOF)
        return (0);
      value >>= 6;
    } /* while */
  return (1);
} // OutputBase64Number //

//
// Write out a Message-ID to a file stream for the next message.
// Returns zero on error.  The next time this function is called,
// it will produce the next Message-ID in sequence.
//
int	WriteMsgIdSpec (FILE *file)
{
  if (fputc ('<',file) == EOF)
    return (0);
  if (!OutputBase64Number (file,CurrentDateTime,6) ||
      !OutputBase64Number (file,TickValue,2) ||
      !OutputBase64Number (file,MessageNumber,1))
    return (0);
  ++MessageNumber;
  return (fprintf (file,"%s@%s>",MailerIdent,HostName) != EOF);
} // WriteMsgIdSpec //
----cut-here----

-- 
Rhys Weatherley, Brisbane, Queensland, Australia.   G'day!!
e-mail: rhys@meteor.brisnet.org.au (normal) or rhys@cs.uq.oz.au (long msgs)