/* * @(#)dequeue_messages.c 1.6 06/22/98 SMI * * Copyright 1997 by Sun Microsystems, Inc. * All rights reserved * * Dequeues messages from the specified channel, * and display an abstract of each on standard output. * If the channel is not specified, the channel name used is "custom". * * Syntax: * dequeue_messages [ -c channel_name ] */ #include #include #include #include immd_t md; 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 dequeue_messages [ -c channel_name ]\n\n"); return; } static void display_header() { char *result; int i, status; imhdr_t hdr = NULL; /* read the header */ check( "immd_read_header", immd_read_header( md, &hdr)); /* Display each header */ for ( i = HL_FIRST_HEADER ; i < HL_LAST_HEADER ; i++ ) { result = NULL; while ( imhdr_get_line( hdr, i, &result) > 0 ) { printf( "HEADER| %s\n", result); imhdr_free_line(hdr, result); } } /* free the header */ imhdr_free( hdr); return; } static void display_body() { int body_len = 0, status; char *text; while( body_len < 1000 && immd_read_text( md, &text) == 0 ) { printf( " BODY| %s", text); body_len += 1; } printf( "...\nEND OF MESSAGE\n\n"); return; } main ( int argc, char **argv) { extern char *optarg; char c; char *channel; char *rcpt, *from, *orig_rcpt; int size, flags; 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)); while ( immd_get_message ( md, &from, &size) == 0 ) { printf( "Envelope From: %s\n", from); /* display the recipients */ while ( immd_get_recipient( md, &flags, &rcpt, &orig_rcpt) == 0 ) { printf( " Envelope To: %s\n", rcpt); } /* display the header and body */ display_header(); display_body(); /* dequeue the message */ check( "immd_dequeue", immd_dequeue( md)); } immd_end( md); imta_end(); exit( EX_OK); }