#include #include #include #include #include void usage (char * p) { fprintf (stderr, "usage: %s folder\n", p); exit (1); } void show (char * p, char * f, int neu) { char * mailpath; char ch; char buf[75]; int body = 0; FILE * fp; mailpath = malloc (strlen (p) + strlen (f) + 2); assert (mailpath); strcpy (mailpath, p); strcat (mailpath, "/"); strcat (mailpath, f); fp = fopen (mailpath, "r"); if (!fp) return; if (neu) { printf ("NEU (%s):\n", f); } else { printf ("ALT (%s):\n", f); } while (1) { if (!fgets (buf, 70, fp)) break; if (!body && (strlen (buf) == 1) && (buf[0] == '\n')) { body = 1; continue; } if (!strlen (buf) || (buf[strlen (buf)-1] != '\n')) { strcat (buf, "...\n"); while (1) { ch = fgetc (fp); if (ch < 0) break; if (ch == '\n') break; } } if (body) { printf ("%s", buf); if (body >= 3) break; body++; continue; } if (strncmp (buf, "Subject: ", strlen ("Subject: ")) == 0) { printf ("%s", buf); continue; } if (strncmp (buf, "From: ", strlen ("From: ")) == 0) { printf ("%s", buf); continue; } } printf ("---\n"); fclose (fp); } int main (int argc, char **argv) { char * path; DIR * dp; struct dirent * dent; if (argc != 2) usage (argv[0]); path = malloc (strlen (argv[1] + 5)); assert (path); strcpy (path, argv[1]); strcat (path, "/new"); dp = opendir (path); assert (dp); while ((dent = readdir (dp))) { if (dent->d_name[0] == '.') continue; show (path, dent->d_name, 1); } closedir (dp); strcpy (path, argv[1]); strcat (path, "/cur"); dp = opendir (path); assert (dp); while ((dent = readdir (dp))) { if (dent->d_name[0] == '.') continue; show (path, dent->d_name, 0); } closedir (dp); return 0; }