/* * @(#)decode_mime_messages.c 1.4 06/22/98 SMI * * Copyright 1997 by Sun Microsystems, Inc. * All rights reserved * * Decodes queued MIME messages and displays the output of the parsing. * * Syntax: * decode_mime_messages [ -c channel_name ] */ #include #include #include #include immd_t md; static void check (int status) { if ( status != 0 ) { printf( "ERROR: %s\n", (char *)imta_error(status)); imta_end(); exit (status); } return; } static void usage() { printf("Usage:\n decode_mime_messages [ -c channel_name ]\n\n"); return; } int output_line (void * passed_context, const char *line, int line_len) { printf ("%.*s\n", line_len, line); return (IMTARC_OK); } int output_block (void * passed_context, const char *line, int line_len) { printf ("%d bytes of binary data\n", line_len); return (IMTARC_OK); } int output_header ( void * passed_context, imhdr_t hdr, int associated_part, int level, int index) { int i; char *result; printf( "\nMessage header: level = %d, index = %d, associated_part = %d\n", level, index, associated_part); /* 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); } } if (associated_part == 2) { printf ("\nText message body: level = %d, index = %d\n", level, index); } else if (associated_part == 1) { printf ("\nBinary message body: level = %d, index = %d\n", level, index); } return(IMTARC_OK); } main ( int argc, char **argv) { extern char *optarg; char c; char *channel = NULL; char *rcpt, *from, *orig_rcpt; int size, flags; /* 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( channel) ); check( immd_init ( &md)); while ( immd_get_message ( md, &from, &size) == 0 ) { printf ("\n"); while ( immd_get_recipient( md, &flags, &rcpt, &orig_rcpt) == 0 ) { printf ("Envelope To: %s\n", rcpt); } printf ("\n"); check( immd_mime_decode( md, NULL, output_header, output_line, output_block)); check( immd_dequeue (md)); } immd_end(md); imta_end(); free(channel); exit(EX_OK); }