Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Mar 2001 09:35:49 +1200
From:      Jonathan Chen <jonathan.chen@itouch.co.nz>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        questions@FreeBSD.ORG
Subject:   Re: rotating .signatures?
Message-ID:  <20010322093549.A94461@itouchnz.itouch>
In-Reply-To: <20010321103918.P12319@fw.wintelcom.net>; from bright@wintelcom.net on Wed, Mar 21, 2001 at 10:39:18AM -0800
References:  <20010321103918.P12319@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Wed, Mar 21, 2001 at 10:39:18AM -0800, Alfred Perlstein wrote:
> I've seen people that have rotating .signatures for email,
> anyone know how to do this with mutt?

I've got in my ~/.muttrc:

	set signature="~/bin/pick-sig|"

which is a small C program which picks up a random signature from
~/.signatures.
-- 
Jonathan Chen <jonathan.chen@itouch.co.nz>
----------------------------------------------------------------------
                                      Opportunities are seldom labeled

--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pick-sig.c"

/*
 *	Pick a signature from ~/.signatures directory
 *
 *	jonathan.chen@itouch.co.nz
 */
#include	<stdio.h>
#include	<stdlib.h>
#include	<sys/types.h>
#include	<dirent.h>

#define	SIGNATURE_DIR	".signatures"

main ()
{
	int sigcount;
	DIR * sigdir;
	char path [1024];
	int exit_val = EXIT_SUCCESS;

	sprintf (path, "%s/%s", getenv ("HOME"), SIGNATURE_DIR);

	/*
	 *	Open the directory, count the number of entries
	 *
	 */
	if (!(sigdir = opendir (path)))
		return EXIT_FAILURE;

	for (sigcount = 0; readdir (sigdir); sigcount++);

	sigcount -= 2;				/* don't count . and .. */
	if (sigcount < 0)
	{
		fprintf (stderr, "Internal error on counting files\n");
		exit_val = EXIT_FAILURE;
		goto end;
	}

	if (sigcount > 0)
	{
		int pick;
		int i;
		struct dirent * entry;
		FILE * sigfile;
		char line [1024];

		srandomdev ();
		pick = random () % sigcount;

		rewinddir (sigdir);

		for (i = -2; i <= pick; i++)
			entry = readdir (sigdir);

		sprintf (path, "%s/%s/%s",
			getenv ("HOME"),
			SIGNATURE_DIR,
			entry -> d_name);

		if (!(sigfile = fopen (path, "r")))
		{
			exit_val = EXIT_FAILURE;
			goto end;
		}

		while (fgets (line, sizeof (line), sigfile))
			fputs (line, stdout);

		fclose (sigfile);
	}

end:
	closedir (sigdir);
	return exit_val;
}

--uAKRQypu60I7Lcqm--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010322093549.A94461>