/* GNU Mailutils -- a suite of utilities for electronic mail Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Mailutils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Mailutils; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include int main ( int argc, const char **argv ) { char * from; char *subject; char *hdr_status; char *hdr_status_src; mailbox_t mbox_src; mailbox_t mbox_dst; size_t msgno, total, tot2 = 0; int status; /* Register the formats. */ // mu_register_all_mbox_formats (); list_t bookie = 0; registrar_get_list ( &bookie ); list_append ( bookie, path_record ); list_append ( bookie, mbox_record ); list_append ( bookie, pop_record ); // list_append (bookie, mh_record);\ // list_append (bookie, maildir_record);\ /* Setup the mailboxes */ status = mailbox_create_default ( &mbox_src, argv[ 1 ] ); if ( status != 0 ) { mu_error ( "mailbox_create: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_create_default ( &mbox_dst, argv[ 2 ] ); if ( status != 0 ) { mu_error ( "mailbox_create: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_open ( mbox_src, MU_STREAM_RDWR ); if ( status != 0 ) { mu_error ( "mailbox_open: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_open ( mbox_dst, MU_STREAM_RDWR ); if ( status != 0 ) { mu_error ( "mailbox_open: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } /* Go through the source messages, append and change field */ mailbox_messages_count ( mbox_src, &total ); for ( msgno = 1; msgno <= total; msgno++ ) { message_t msg; message_t msg_dst; header_t hdr; header_t hdr_dst; if ( ( status = mailbox_get_message ( mbox_src, msgno, &msg ) ) != 0 || ( status = message_get_header ( msg, &hdr ) ) != 0 ) { mu_error ( "Error message: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } char uidl[ 128 ]; message_get_uidl( msg, uidl, 128, NULL ); if ( header_aget_value ( hdr, MU_HEADER_FROM, &from ) ) from = strdup ( "(NO FROM)" ); if ( header_aget_value ( hdr, MU_HEADER_SUBJECT, &subject ) ) subject = strdup ( "(NO SUBJECT)" ); if ( header_aget_value ( hdr, MU_HEADER_STATUS, &hdr_status_src ) ) hdr_status_src = strdup ( "(NO STATUS)" ); /* Try to set the status to something */ // status = header_set_value ( hdr, MU_HEADER_STATUS, "OR", 1 ); // if ( status != 0 ) // { // mu_error ( "header_set_value: %s", mu_strerror ( status ) ); // exit ( EXIT_FAILURE ); // } /* Try to set something */ status = header_set_value ( hdr, "X-XXX", "Testing", 1 ); if ( status != 0 ) { mu_error ( "header_set_value: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_append_message ( mbox_dst, msg ); if ( status != 0 ) { mu_error ( "mailbox_open: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } // This stops the EINVAL returned from next mailbox_get_message() mailbox_messages_count ( mbox_dst, &tot2 ); printf ( "%d, %d\n", msgno, tot2 ); status = mailbox_get_message ( mbox_dst, msgno, &msg_dst ); if ( status != 0 ) { mu_error ( "mailbox_get_message: %d %s", msgno, mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = message_get_header ( msg_dst, &hdr_dst ); if ( status != 0 ) { mu_error ( "mailbox_get_header: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } /* Try to set something */ status = header_set_value ( hdr_dst, "X-XXX", "Testing", 1 ); if ( status != 0 ) { mu_error ( "header_set_value: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } attribute_t attr = NULL; status = message_get_attribute( msg_dst, &attr ); if ( status != 0 ) { mu_error ( "message_get_attribute: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } attribute_set_read( attr ); /* Test the value of status is set */ if ( header_aget_value ( hdr_dst, MU_HEADER_STATUS, &hdr_status ) ) hdr_status = strdup ( "(NO STATUS)" ); //printf ("%s\t%s\n", from, subject); printf ( "%d uild is [%s] src status is [%s] dst status is [%s]\n", msgno, uidl, hdr_status_src, hdr_status ); free ( from ); free ( subject ); free ( hdr_status ); free ( hdr_status_src ); // attribute_destroy ( &attr, NULL ); // header_destroy ( &hdr_dst, NULL ); // message_destroy ( &msg_dst, NULL ); // hdr_dst = NULL; // msg_dst = NULL; } /* flush (which also sets "seen") */ // status = mailbox_flush( mbox_dst, 1 ); status = mailbox_save_attributes(mbox_dst); if ( status ) { mu_error ( "mailbox_save_attributes: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_expunge ( mbox_dst ); if ( status ) { mu_error ( "mailbox_expunge: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_close ( mbox_src ); if ( status != 0 ) { mu_error ( "mailbox_close: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } status = mailbox_close ( mbox_dst ); if ( status != 0 ) { mu_error ( "mailbox_close: %s", mu_strerror ( status ) ); exit ( EXIT_FAILURE ); } mailbox_destroy ( &mbox_src ); mailbox_destroy ( &mbox_dst ); return 0; }