Commit 4588f3b3 4588f3b378234e4af5a418bb7fe75c7c77a5c362 by Sean 'Shaleh' Perry

fleshed out mh_open() some more

1 parent 38716599
1 2000--5-19 Sean 'Shaleh' Perry <shaleh@debian.org>
2
3 * libmailbox/mh.c: fleshed out mh_open() some more
4
1 2000-05-18 Sean 'Shaleh' Perry <shaleh@debian.org> 5 2000-05-18 Sean 'Shaleh' Perry <shaleh@debian.org>
2 6
3 * libmailbox/mh.c: fleshed out mh_open() some more 7 * libmailbox/mh.c: fleshed out mh_open() some more
......
...@@ -49,7 +49,7 @@ maildir_open (mailbox * mbox) ...@@ -49,7 +49,7 @@ maildir_open (mailbox * mbox)
49 alloced = 10; 49 alloced = 10;
50 50
51 /* process the new directory */ 51 /* process the new directory */
52 while ((entry = readdir (data->new)) && (entry != NULL)) 52 while (entry = readdir (data->new))
53 { 53 {
54 /* no dot files */ 54 /* no dot files */
55 if (entry->d_name[0] != '.') 55 if (entry->d_name[0] != '.')
...@@ -71,7 +71,7 @@ maildir_open (mailbox * mbox) ...@@ -71,7 +71,7 @@ maildir_open (mailbox * mbox)
71 } 71 }
72 72
73 /* then the cur directory */ 73 /* then the cur directory */
74 while ((entry = readdir (data->cur)) && (entry != NULL)) 74 while (entry = readdir (data->cur))
75 { 75 {
76 if (entry->d_name[0] != '.') 76 if (entry->d_name[0] != '.')
77 { 77 {
......
...@@ -28,6 +28,7 @@ int ...@@ -28,6 +28,7 @@ int
28 mh_open (mailbox * mbox) 28 mh_open (mailbox * mbox)
29 { 29 {
30 int i; 30 int i;
31 unsigned long seq_num = 0;
31 struct dirent *entry; 32 struct dirent *entry;
32 mh_data *data; 33 mh_data *data;
33 34
...@@ -42,9 +43,10 @@ mh_open (mailbox * mbox) ...@@ -42,9 +43,10 @@ mh_open (mailbox * mbox)
42 /* process directory */ 43 /* process directory */
43 while (entry = readdir (data->dir)) 44 while (entry = readdir (data->dir))
44 { 45 {
45 unsigned long seq_num;
46 char *foo = NULL; 46 char *foo = NULL;
47 char fname[PATH_MAX]; 47 char fname[PATH_MAX];
48 char line[80];
49 FILE *fp;
48 if (entry->d_name[0] == '.') 50 if (entry->d_name[0] == '.')
49 { 51 {
50 if (strcmp(entry->d_name, ".mh_sequences") == 0) 52 if (strcmp(entry->d_name, ".mh_sequences") == 0)
...@@ -58,10 +60,26 @@ mh_open (mailbox * mbox) ...@@ -58,10 +60,26 @@ mh_open (mailbox * mbox)
58 seq_num = strtoul (entry->d_name, &foo, 10); 60 seq_num = strtoul (entry->d_name, &foo, 10);
59 if (*foo != '\0') /* invalid sequence number */ 61 if (*foo != '\0') /* invalid sequence number */
60 continue; /* TODO: handle this better? */ 62 continue; /* TODO: handle this better? */
61 printf ("message: %ld\r", seq_num); 63 sprintf(fname, "%s/%ld", mbox->name, seq_num);
64 if ((fp = fopen(fname, "r")) == NULL)
65 continue; /* TODO: handle the error */
66 /* TODO: handle corrupt files */
67 while (fgets (line, 80, fp))
68 {
69 if ((line[0] == '\r' && line[1] == '\n') || line[0] == '\n')
70 {
71 /* TODO: handle marking the message body */;
72 break;
73 }
74 }
75 fclose (fp);
76 /* TODO: create message structure */
62 mbox->messages++; 77 mbox->messages++;
63 } 78 }
64 79
80 /* store next sequence number to use */
81 data->sequence = seq_num + 1;
82
65 mbox->_data = data; 83 mbox->_data = data;
66 #if 0 84 #if 0
67 mbox->_close = mh_close; 85 mbox->_close = mh_close;
...@@ -74,9 +92,6 @@ mh_open (mailbox * mbox) ...@@ -74,9 +92,6 @@ mh_open (mailbox * mbox)
74 mbox->_get_body = mh_get_body; 92 mbox->_get_body = mh_get_body;
75 mbox->_get_header = mh_get_header; 93 mbox->_get_header = mh_get_header;
76 #endif 94 #endif
77 chdir(old_dir);
78
79 fprintf(stderr, "\r\n%d messages read\n", mbox->messages);
80 95
81 return 0; 96 return 0;
82 } 97 }
......