[PREVIOUS CHAPTER] [NEXT CHAPTER]
10 Library Functions


I explain useful (I believe) library functions in this chapter.
Anyway here we go though choice depends on me.  The choice must be
random and does not cover the whole ;-D.

10.1	daemon (libutils.pl)


Let the current execution program be a daemon.


	&use('utils');
	&daemon;


Example:
	&use('utils');
	&daemon;
	work under daemon mode


&daemon detaches the current TTY and close STDIN,STDOUT,STDERR.


Example:

	$FML_EXIT_HOOK .= q#
		&use('utils');
		&daemon;
		exec("$LIBDIR/bin/cron.pl $DIR -a");
	#;


You may be required to set $NOT_USE_TIOCNOTTY? This function works well
on 4.x BSD, but I don't know how it works on other OS's.


10.2	Sendmail (libsmtp.pl)

SYNOPSIS
	&Sendmail($to, $subject, $body, @to);


	$to		recipient
	$subject	subject of mail to send
	$body		body of mail to send
	@to		recipients except $to 

10.3	SendFile (libsmtp.pl)

SYNOPSIS
	&SendFile($to, $subject, $file, $zcat, @to);


	$to		recipient
	$subject	subject of mail to send
	$file		a file to send
	$zcat		conversion flag (not used)
	@to		recipients except $to 


10.4	NeonSendFile (libsmtp.pl)


handling plural recipients and plural files to send.

SYNOPSIS
	&NeonSendFile(*to, *subject, *files);


	@to		recipients (array)
	$subject	subject of mail to send
	@files		array of files to send

10.5	Addr2FQDN              (fml.pl)

SYNOPSIS:
	&Addr2FQDN($addr);


If given $addr has no '@', we convert it to

	$addr@$FQDN


If $addr contains '@', return $addr.

10.6	AddressMatch           (fml.pl)

SYNOPSIS:
	&AddressMatching($addr1, $addr2)


compare $addr1 and $addr2, return 1 if they are the same.
return 0 if different.

10.7	MailListMemberP        (fml.pl)

SYNOPSIS:
	&MailListMemberP($addr)


search $addr in lists of member (member files are listed in
@MEMBER_LIST) and return the file name in which $addr if $addr is
found. return $NULL if fails.

10.8	MailListActiveP        (fml.pl)

SYNOPSIS:
	&MailListActiveP($addr)


search $addr in lists of active member (active member files are listed
in @ACTIVE_LIST) and return the file name in which $addr if $addr is
found.

10.9	Append2                (fml.pl)

SYNOPSIS:
	&Append2($string, $file)

appends $string to $file

10.10	AutoRegist             (libutils.pl)

SYNOPSIS:
	&AutoRegist(*Envelope);
	&AutoRegist(*Envelope, $string);


Auto Registration routine. The argument is *Envelope or *Envelope and
$string. If $string is given, the routine checks $string as an input.
If not, $Envelope{'Body'} which is mail body. 

10.11	ChangeMemberList       (libfml.pl)


Apply &DoChangeMemberList(@_) recursively up to
$ADDR_CHECK_MAX(default 10) times. It checks the given address little
by little severely. For example we check the address

	fukachan@sapporo.iij.ad.jp


up to 3 level, that is "iij.ad.jp" in default. If both
fukachan@iij.ad.jp and fukachan@sapporo.iij.ad.jp exist in member
file, we cannot determine this mail is from which person?  Hence we
require changing the address check level dynamically. Secondary FML
checks up to 4 levels, that is "sapporo.iij.ad.jp" and matches in
exacet and return TRUE.


Example: a list have two similar addresses with different levels.

	fukachan@iij.ad.jp
	fukachan@sapporo.iij.ad.jp


10.12	ChangePasswd           (libcrypt.pl)

SYNOPSIS:
	&ChangePasswd($PASSWD_FILE, $addr, $new)


Change the password for the address $addr. The new password is $new
and the password file is $PASSWD_FILE.  $new is a plain password.

10.13	CheckMember            (fml.pl)


obsolete. left for compatibility.

SYNOPSIS:
	 &CheckMember($addr, $list);


Check whether $addr appears in $list or not. 1 if found, 0 if fails.

10.14	CmpPasswd              (libcrypt.pl)

SYNOPSIS:
	&CmpPasswd($encrypt, $plain-passwd)


compare encrypted password $encrypt and input plain password
$plain-passwd.

10.15	CmpPasswdInFile        (libcrypt.pl)

SYNOPSIS:
	&CmpPasswdInFile($PASSWD_FILE, $addr, $pass)


check whether $addr with password $pass is valid in $PASWD_FILE.
If valid, $addr is authenticated.

10.16	Conv2mailbox           (fml.pl)

SYNOPSIS:
    &Conv2mailbox($from, *e)


Cut out only user@domain part from given string $from.

10.17	DecodeMimeStrings      (libMIME.pl)

SYNOPSIS:
	$s = &DecodeMimeStrings($s);


Decode MIME string to Japanese and return it.

10.18	Flock                  (fml.pl)

SYNOPSIS:
	&Flock();


flock(2) to $FP_SPOOL_DIR. 


After $Timeout{'flock'} (default 3600) under locked, we trap signal
SIGALRM and runs &Tick. In default fml.pl exits after timeout.

10.19	Funlock                (fml.pl)


unlock the lock on $FP_SPOOL_DIR. see flock(2)

10.20	GetID                  (libfml.pl)

SYNOPSIS:
	&GetID;


Return value in $SEQUENCE_FILE where the value is the last article
sequence.

10.21	GetTime                (fml.pl)

SYNOPSIS:
	&GetTime;


runs localtime(); and sets several global variables such as:

    $Now = sprintf("%02d/%02d/%02d %02d:%02d:%02d", 
		   $year % 100, $mon + 1, $mday, $hour, $min, $sec);
    $MailDate = sprintf("%s, %d %s %d %02d:%02d:%02d %s", 
			$WDay[$wday], $mday, $Month[$mon], 
			1900 + $year, $hour, $min, $sec, $TZone);

    $CurrentTime = sprintf("%04d%02d%02d%02d%02d", 
			   1900 + $year, $mon + 1, $mday, $hour, $min);

10.22	Lock                   (fml.pl)

SYNOPSIS:
	&Lock;

		&Flock;
	else 
		require liblock.pl;
		&V7Lock;


	if $USE_FLOCK 
		&Flock;
	else 
		# link(2) based lock algorithm (liblock.pl)
		require liblock.pl;
		&V7Lock;

10.23	Log                    (fml.pl)

SYNOPSIS:
	&Log($s);


Append $s string to $LOGFILE with date.

10.24	LogWEnv                (fml.pl)

SYNOPSIS:
	&LogWEnv($s, *e);


&LogWEnv($s, *e); is the same as

	&Log($s)
	$e{'message'} .= "$s\n";


Both Logs $LOGFILE and the messages &Notify uses.


10.25	Lookup (fml.pl)

SYNOPSIS:
	 &Lookup($addr, $list);


Check whether $addr appears in $list or not. 1 if found, 0 if fails.	


10.26	MailListActiveP	(fml.pl)

SYNOPSIS:
	&MailListActiveP($address);


ML member list contains $address? It return the file which contains it
or NULL if fails. 
Caution: $address is a member, so it is used in authenticaion. Whereas
this does not imply $address is a recipient in fml.


10.27	MailListMemberP	(fml.pl)

SYNOPSIS:
	&MailListMemberP($address);


$address is a recipient? This returns the file which contains it or
NULL if fails.


10.28	Mesg                   (fml.pl)

SYNOPSIS:
	&Mesg(*Envelope, $s);


&Notify sends a content $Envelope{'message'} to a user (From:
address). &Mesg() appends $s to $Envelope{'message'}.

	$Envelope{'message'} .= "$s\n";

10.29	NewSyslog              (libnewsyslog.pl)

newsyslog(8) like function.

10.30	Notify                 (fml.pl)

SYNOPSIS:
	&Notify;


Send an error, warning status report of commands mail reply.  The
content is $Envelope{'message'}.  The recipient is
$Envelope{'message:h:to'}, if not defined $Envelope{'Addr2Reply:'}.
The plural recipients is available by setting
$Envelope{'message:h:@to'}. The return mail subject is
$Envelope{'message:h:subject'}, if not defined, "fml status report
$ML_FN".

   Subject:	$Envelope{'message:h:subject'}


In the last of mail body, &Notify appends the buffer generated by a
function $PROC_GEN_INFO (default 'GenInfo') .


Also &Notify the buffer $Envelope{'error'} to ML maintainers.


In this mail, &Notify uses a good bye phrase and a face mark:D. You
define it by

	$GOOD_BYE_PHRASE	(good bye phrase)
	$FACE_MARK		(face mark)


	$GOOD_BYE_PHRASE = "\tBe seeing you!   ";


10.31	RunHooks               (fml.pl)

SYNOPSIS:
	&RunHooks;


If $FML_EXIT_HOOK is defined, runs it.

	eval $FML_EXIT_HOOK

10.32	ExecNewProcess		(fml.pl)


If $FML_EXIT_PROG is defined, runs it 

	exec $FML_EXIT_PROG;


10.33	SecureP                (fml.pl)

SYNOPSIS:
	&SecureP($request);


Check whether $request is safe or unsafe. Please use %SECURE_REGEXP
for an exceptional security check.

10.34	SendBackInOrder     (libfop.pl)

SYNOPSIS:
	&SendBackInOrder($returnfile, $total, $subj, $sleeptime, @to)

	$subj		Subject: 


	$returnfile	file to send
	$total		the number of split files
	$subj		subject
	$sleeptime	send once each $sleeptime
	@to		recipients


10.35	SocketInit             (libsmtp.pl)

SYNOPSIS:
	&SocketInit;


Initialize socket functions.

10.36	TurnOverW0             (libnewsyslog.pl)

SYNOPSIS:
	&NewSyslog'TurnOverW0($LOG_MESSAGE_ID);#';


Runs newsyslog. Example: runs newsyslog over $LOG_MESSAGE_ID.

10.37	Unlock                 (fml.pl)


Unlcok.

10.38	Warn                   (fml.pl)

SYNOPSIS:
	&Warn($subject, $body);


&Warn is the same as

	&Sendmail($MAINTAINER, $subject, $body);


Mails to $MAINTAINER. 

10.39	WholeMail              (fml.pl)

SYNOPSIS:	
	&WholeMail;


Return the whole mail with 3 SPACE CHARACTERS indent.  The indent
prevents strange MTA or MUA converting the mail body.  No conversion
is important for debug. I want to receive raw mail for debug!


If $MIME_CONVERT_WHOLEMAIL is set, we try MIME decoding of Japanese of
the mail body.

10.40	eval                   (fml.pl)

SYNOPSIS:
	&eval($eval_string)


Evaluate $eval_string.

10.41	ipc                    (libutils.pl)

SYNOPSIS:
	&ipc(*ipc, *r);

=
Interface of InterProcess Communication based on Berkeley Socket mechanism.


	$ipc{'host'}	host
	$ipc{'serve'}	port
	$ipc{'tcp'}	TCP/IP
	$ipc{'pat'}	struct sockaddr
	@ipc		input strings (array)
	$r		return value

10.42	system                 (libutils.pl)

SYNOPSIS:
	&system($s, $out, $in, $read, $write)


Executes $s. OUT FILE is $out, IN is $in. OUT FILE HANDLE is $write,
IN is $read.


If $s matches

    /[\$\&\*\(\)\{\}\[\]\'\\\"\;\\\\\|\?\<\>\~\`]/


&system does not run for security.

[PREVIOUS CHAPTER] [NEXT CHAPTER]