Hi. I'm having a little trouble figuring this problem out. What I need the program to do is take an email inbox and print out only the Headers for each message. Assuming each max line length to be 1024. I can read the file line by line but I don't know how to pick out specific lines.

Sample input file (sample.mbox):
From ocfs2-devel-bounces@oss.oracle.com Wed May 18 18:33:55 2005
Return-Path: <ocfs2-devel-bounces@oss.oracle.com>

Hello,

This is OCFS2, a shared disk cluster file system which we hope will be
included in the kernel.

We think OCFS2 has many qualities which make it particularly
interesting as a cluster file system. Please consider ...

From user-mode-linux@lists.sourceforge.net Wed May 18 18:36:00 2005
Return-Path: <user-mode-linux-devel-admin@lists.sourceforge.net>

Ok, let me have an example.

suppose a user argument has virtual address 0xa0, corresponding UML
physical address 0xb0, and real physical address 0x10. so, when the
user process tries to access 0xa0 for the first time, the UML kernel
should let host kernel know there will be 0xa0 -> 0x10 mapping. how
does the UML kernel make another process's address map to the same
physical page it has? and how does the UML kernel keep track of 0xa0
-> 0xb0 mapping? maybe the same page table mechanism as host Linux? (i
guess so, though)

Thanks a lot!


From openib-general-bounces@openib.org Wed May 18 18:36:08 2005
Return-Path: <openib-general-bounces@openib.org>

William Jordan wrote:
> Sean,
> You mentioned that the cm_id leak was fixed, but I don't see a patch
> for it, so I'm submitting one.
>

When I try to apply this patch, most of it is rejected.

- Sean

From D-2-721494-20549853-2-153912-US1-EBB1BBA6@xmr3.com Mon Jan 5
Content-Type: multipart/alternative;
boundary=MEboundary-20549853-5-1073330144
Status: RO
X-Status:
X-Keywords:
X-UID: 5

That should be fine.

- Sean

Sample output:
1: From ocfs2-devel-bounces@oss.oracle.com Wed May 18 18:33:55 2005
2: From user-mode-linux@lists.sourceforge.net Wed May 18 18:36:00 2005
3: From openib-general-bounces@openib.org Wed May 18 18:36:08 2005
4: From D-2-721494-20549853-2-153912-US1-EBB1BBA6@xmr3.com Mon Jan 5

Here's what I have so far:

#include <stdio.h>

void main() {
  FILE *mbox;
  char filename[40];
  char line[1024];
  int count=0;

  printf("Enter the file name of your mailbox: ");
  gets(filename);

  if((mbox = fopen(filename, "r")) == NULL) {
    printf("Error Opening File.\n");
  }

  while(fgets(line, sizeof(line), mbox) != NULL) {
    /* maybe do something here to find lines begining with "From" */
    count++;
    printf("%d: %s", count, line);
  }
  fclose(mbox);
}

You can use strstr() to find a sub-string (word), within a string. In your case though, you just need to find line[0] == 'F', and that's your line. :)

I would go as far as testing it a bit further, though:

if((line[0]=='F') && (line[1]=='r') && (line[2]=='o') && line[3]=='m') {
    //rest of your code, in here.
}

Should be just what you need.

Great, thank you. I guess I was just over thinking the problem. Now I have to expand the idea and ask the user to select a "From" line and then print the corresponding email body.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.