/* * @(#)reenqueue_messages.c 1.4 06/18/98 SMI * * Copyright 1997 by Sun Microsystems, Inc. * All rights reserved * * Dequeues messages from the specified channel, performs a rot13 * permutation on the message body, and re-enqueues * them towards the originator of each message. * If the channel is not specified, the channel name used is "custom". * * Syntax: * reenqueue_messages [ -c channel_name ] */ #include #include #include #include immd_t md; imme_t me; char rot13 (char c) { if ('A' <= c && c <= 'Z') { return (((c - 'A' + 13) % 26) + 'A'); } else if ('a' <= c && c <= 'z') { return (((c - 'a' + 13) % 26) + 'a'); } else { return (c); } } static void check ( char *func, int status) { if ( status != 0 ) { printf( "ERROR %d in %s: %s\n", status, func, (char *)imta_error(status)); imta_end(); exit (status); } return; } static void usage() { printf("Usage:\n reenqueue_messages [ -c channel_name ]\n\n"); return; } main ( int argc, char **argv) { imhdr_t hdr = NULL; int size, flags; extern char *optarg; char c; char *channel; char *rcpt, *from, *orig_rcpt, *txt; int txt_len; int i; channel = NULL; /* parse command line */ while ((c = getopt(argc, argv, "c:")) != EOF) { switch (c) { case 'c': /* the recipient */ channel = (char *)strdup( optarg); break; default: usage(); exit( EX_USAGE); } } if ( channel == NULL ) channel = "custom"; /* initialize */ check( "imta_init", imta_init( channel) ); check( "immd_init", immd_init ( &md)); check( "imme_init", imme_init( &me)); while ( immd_get_message( md, &from, &size) == 0 ) { if ( *from ) { while ( immd_get_recipient( md, &flags, &rcpt, &orig_rcpt) == 0 ); check( "imme_start_envelope", imme_start_envelope( me, from)); check( "imme_add_recipient", imme_add_recipient( me, 0, 0, from, NULL)); check( "immd_read_header", immd_read_header( md, &hdr)); check( "imme_write_header", imme_write_header( me, hdr)); imhdr_free( hdr); /* read and convert the body of the message being dequeued; * write the converted body in the message being enqueued */ while ( immd_read_text( md, &txt) == 0 ) { txt_len = strlen(txt); for (i = 0; i < txt_len - 1; i++) { txt[i] = rot13 (txt[i]); } check( "imme_write_text", imme_write_text( me, txt)); } /* enqueue the converted message */ check( "imme_enqueue", imme_enqueue( me)); } /* dequeue the processed message */ check( "imme_dequeue", immd_dequeue( md)); } imme_end( me); immd_end( md); imta_end(); exit( EX_OK); }