[gmime-devel] Unable to parse_message
- From: wasiq mohammed <wasiq_md yahoo com>
- To: gmime-devel-list gnome org
- Subject: [gmime-devel] Unable to parse_message
- Date: Sun, 23 Nov 2014 00:36:37 -0800
Hi There,
I am new to gmime and need your help in resolving an issue that I am facing.
I have gmime-2.0 on my fedora. I want to parse an email and retrieve the "From", "to", "Subject" and the body
of the message. This is my program:
static GMimeMessage *parse_message (int fd)
{
GMimeMessage *message;
GMimeParser *parser;
GMimeStream *stream;
/* create a stream to read from the file descriptor */
stream = g_mime_stream_fs_new (fd);
/* create a new parser object to parse the stream */
parser = g_mime_parser_new_with_stream (stream);
/* unref the stream (parser owns a ref, so this object does not actually get free'd until we destroy
the parser) */
g_object_unref (stream);
/* parse the message from the stream */
message = g_mime_parser_construct_message (parser);
/* free the parser (and the stream) */
g_object_unref (parser);
return message;
}
int main (int argc, char **argv)
{
GMimeMessage *message;
InternetAddressList *addressList;
InternetAddress *address;
char *name;
char *subject;
char *from;
char path[100];
char command[100];
char command1[100];
int fd;
int addressListLen = 0;
int i = 0;
if (argc < 2) {
printf ("Usage: a.out <message file>\n");
return 0;
} else {
if ((fd = open (argv[1], O_RDONLY, 0)) == -1) {
fprintf (stderr, "Cannot open message `%s': %s\n", argv[1], g_strerror (errno));
return 0;
}
}
/* init the gmime library */
g_mime_init (0);
/* parse the message */
message = parse_message (fd);
if( !message )
{
printf("Message Parse failure\n");
return 0;
}
else
{
printf("Message Parse Success\n");
}
from = g_mime_message_get_sender( message );
printf("\n From \t : %s\n", from);
printf("\n Reply To \t : %s\n", g_mime_message_get_reply_to( message));
subject = g_mime_message_get_subject(message);
printf("\n Subject \t : %s\n", subject);
printf("\n message_id \t : %s\n", g_mime_message_get_message_id(message));
addressList = g_mime_message_get_all_recipients( message );
addressListLen = internet_address_list_length( addressList );
printf("\n Internet Adress List Length \t : %d\n", addressListLen);
address = internet_address_list_get_address( addressList );
printf("\n Reciepient Name \t : %s\n", internet_address_get_name( address ));
printf("\n Reciepient Addr \t : %s\n", internet_address_get_addr( address ));
return 0;
}
This program is working for some emails. But its not working for other emails. This is what is the output
when it doesnt work:
[wasiq li656-65 gmime]$ ./test 111
Message Parse Success
From : (null)
Reply To : (null)
Subject : (null)
message_id : (null)
Internet Adress List Length : 0
(process:13571): gmime-CRITICAL **: internet_address_get_name: assertion `ia != NULL' failed
Reciepient Name : (null)
(process:13571): gmime-CRITICAL **: internet_address_get_addr: assertion `ia != NULL' failed
Reciepient Addr : (null)
input = (null)
str after first = (null)
str after second = (null)
Path : /home/wasiq/reciepts/(null)
Appreciate any help on this - may be some sample programs or any suggestion on where I am going wrong.
Thanks,
Wasiq Mohammed
[Date Prev][Date Next] [Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]