summaryrefslogtreecommitdiff
path: root/mb.c
diff options
context:
space:
mode:
Diffstat (limited to 'mb.c')
-rw-r--r--mb.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/mb.c b/mb.c
new file mode 100644
index 0000000..7ced833
--- /dev/null
+++ b/mb.c
@@ -0,0 +1,66 @@
+/* Mangle a berkley mbox
+*/
+#include <stdlib.h>
+#include <stdio.h>
+
+void Process(FILE *fp, const char *p);
+
+int main(int argc, char *argv[])
+{
+ int f;
+
+ if (argc==1)
+ Process(stdin,"stdin");
+ else
+ for(f=1;f<argc;f++)
+ Process(fopen(argv[f],"r"),argv[f]);
+
+ return EXIT_SUCCESS;
+}
+
+
+void Quit(const char *p)
+{
+ perror(p);
+ exit(EXIT_FAILURE);
+}
+
+
+void Process(FILE *fp, const char *p)
+{
+ FILE *out=NULL;
+ char buff[1024];
+ char fn[80];
+ int n=1;
+
+ printf("Processing : %s\n",p);
+
+ if (!fp)
+ Quit("fopen");
+
+ sprintf(fn,"%s.dir",p);
+
+ if (mkdir(fn,0777)==-1)
+ Quit("mkdir");
+
+ while(fgets(buff,sizeof buff,fp))
+ {
+ if (strncmp(buff,"From ",5)==0)
+ {
+ if (out)
+ fclose(out);
+
+ sprintf(fn,"%s.dir/%d.txt",p,n++);
+
+ printf("Creating : %s\n",fn);
+
+ if (!(out=fopen(fn,"w")))
+ Quit("fopen");
+ }
+
+ fprintf(out,"%s",buff);
+ }
+
+ fclose(out);
+ fclose(fp);
+}