Skip to content

Instantly share code, notes, and snippets.

@tsupo
Created May 14, 2009 09:46
Show Gist options
  • Select an option

  • Save tsupo/111591 to your computer and use it in GitHub Desktop.

Select an option

Save tsupo/111591 to your computer and use it in GitHub Desktop.
change RMAIL-formatted mail to mbox-formatted mail
/*
* change RMAIL-formatted mail to mbox-formatted mail
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char lineBuffer[200][BUFSIZ];
int line = 0;
void
rmail2mbox( filename )
char *filename;
{
FILE *fp;
char *p, buf[BUFSIZ], d1[4], d2[4], d3[4], d4[5], d5[80];
int cnt = 0, flag = 0, i;
if ( ( fp = fopen( filename, "r" ) ) != NULL ) {
while ( ( p = fgets( buf, BUFSIZ - 1, fp ) ) != NULL ) {
if ( (*p == '_' - '@') && (*(p + 1) == 'L' - '@') ) {
cnt++;
flag = 1;
continue;
}
if ( flag == 1 ) {
if ( (*p >= '0') && (*p <= '9') )
continue;
if ( !strncmp( p, "\tid ", 4 ) ) {
char *q, *r;
if ( ( q = strchr( p, ';' ) ) != NULL ) {
strncpy( d1, q + 2, 3 );
d1[3] = '\0';
sprintf( d2, "%d", atoi( q + 7 ) );
if ( ( r = strchr( q + 7, ' ' ) ) != NULL ) {
strncpy( d3, r + 1, 3 );
d3[3] = '\0';
d4[0] = '1';
d4[1] = '9';
strncpy( d4 + 2, r + 5, 2 );
d4[4] = '\0';
}
else {
strcpy( d3, "Aug" );
strcpy( d4, "1998" );
}
if ( ( r = strchr( q, ':' ) ) != NULL ) {
strcpy( d5, r - 2 );
if ( ( q = strrchr( d5, ':' ) ) != NULL )
*(q + 3) = '\0';
}
else
strcpy( d5, "00:00:00" );
printf( "From xxxxx %s %s %s %s %s\n",
d1, d3, d2, d5, d4 );
flag = 2;
if ( line > 0 )
for ( i = 0; i < line; i++ )
fputs( lineBuffer[i], stdout );
line = 0;
continue;
}
}
strcpy( lineBuffer[line++], p );
}
if ( flag == 2 ) {
if ( *p == '\n' )
flag = 3;
fputs( p, stdout );
continue;
}
if ( flag == 3 ) {
if ( *p == '\n' )
flag = 4;
continue;
}
if ( flag == 4 )
fputs( p, stdout );
}
fclose( fp );
}
}
void
main( argc, argv )
int argc;
char *argv[];
{
int i;
for ( i = 1; i < argc; i++ )
rmail2mbox( argv[i] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment