touch ups
Showing
1 changed file
with
19 additions
and
9 deletions
... | @@ -27,7 +27,6 @@ | ... | @@ -27,7 +27,6 @@ |
27 | int | 27 | int |
28 | mh_open (mailbox * mbox) | 28 | mh_open (mailbox * mbox) |
29 | { | 29 | { |
30 | int i; | ||
31 | unsigned long seq_num = 0; | 30 | unsigned long seq_num = 0; |
32 | struct dirent *entry; | 31 | struct dirent *entry; |
33 | mh_data *data; | 32 | mh_data *data; |
... | @@ -41,25 +40,37 @@ mh_open (mailbox * mbox) | ... | @@ -41,25 +40,37 @@ mh_open (mailbox * mbox) |
41 | return errno; /* set by opendir() */ | 40 | return errno; /* set by opendir() */ |
42 | 41 | ||
43 | /* process directory */ | 42 | /* process directory */ |
44 | while (entry = readdir (data->dir)) | 43 | while ((entry = readdir (data->dir))) |
45 | { | 44 | { |
46 | char *foo = NULL; | 45 | char *foo = NULL; |
47 | char fname[PATH_MAX]; | 46 | char fname[PATH_MAX]; |
48 | char line[80]; | 47 | char line[80]; |
49 | FILE *fp; | 48 | FILE *fp; |
49 | mh_message message; | ||
50 | |||
50 | if (entry->d_name[0] == '.') | 51 | if (entry->d_name[0] == '.') |
51 | { | 52 | { |
52 | if (strcmp(entry->d_name, ".mh_sequences") == 0) | 53 | if (strcmp(entry->d_name, ".mh_sequences") == 0) |
53 | /* TODO: deal with mh sequence files */; | 54 | /* TODO: deal with mh sequence files */; |
54 | continue; | 55 | continue; |
55 | } | 56 | } |
56 | if (entry->d_name[0] == ',') | ||
57 | /* file marked for deletion */; | ||
58 | 57 | ||
59 | /* TODO: handle ERANGE */ | 58 | if (entry->d_name[0] == ',') |
60 | seq_num = strtoul (entry->d_name, &foo, 10); | 59 | { |
60 | message.deleted = 1; | ||
61 | seq_num = strtoul ((entry->d_name) + 1, &foo, 10); | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | /* TODO: handle ERANGE */ | ||
66 | seq_num = strtoul (entry->d_name, &foo, 10); | ||
67 | } | ||
61 | if (*foo != '\0') /* invalid sequence number */ | 68 | if (*foo != '\0') /* invalid sequence number */ |
62 | continue; /* TODO: handle this better? */ | 69 | { |
70 | printf("skipping invalid message: %s\n", entry->d_name); | ||
71 | continue; /* TODO: handle this better? */ | ||
72 | } | ||
73 | |||
63 | sprintf(fname, "%s/%ld", mbox->name, seq_num); | 74 | sprintf(fname, "%s/%ld", mbox->name, seq_num); |
64 | if ((fp = fopen(fname, "r")) == NULL) | 75 | if ((fp = fopen(fname, "r")) == NULL) |
65 | continue; /* TODO: handle the error */ | 76 | continue; /* TODO: handle the error */ |
... | @@ -68,12 +79,11 @@ mh_open (mailbox * mbox) | ... | @@ -68,12 +79,11 @@ mh_open (mailbox * mbox) |
68 | { | 79 | { |
69 | if ((line[0] == '\r' && line[1] == '\n') || line[0] == '\n') | 80 | if ((line[0] == '\r' && line[1] == '\n') || line[0] == '\n') |
70 | { | 81 | { |
71 | /* TODO: handle marking the message body */; | 82 | fgetpos(fp, &message.body); |
72 | break; | 83 | break; |
73 | } | 84 | } |
74 | } | 85 | } |
75 | fclose (fp); | 86 | fclose (fp); |
76 | /* TODO: create message structure */ | ||
77 | mbox->messages++; | 87 | mbox->messages++; |
78 | } | 88 | } |
79 | 89 | ... | ... |
-
Please register or sign in to post a comment