Switch to unified view

a b/src/bincimapmime/trbinc.cc
1
#ifndef   lint
2
static char rcsid [] = "@(#$Id: trbinc.cc,v 1.1 2005-03-25 09:40:27 dockes Exp $  (C) 1994 CDKIT";
3
#endif
4
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <unistd.h>
8
#include <errno.h>
9
#include <string.h>
10
#include <fcntl.h>
11
12
#include "mime.h"
13
14
static char *thisprog;
15
16
static char usage [] =
17
    "trbinc <mboxfile> \n\n"
18
    ;
19
static void
20
Usage(void)
21
{
22
    fprintf(stderr, "%s: usage:\n%s", thisprog, usage);
23
    exit(1);
24
}
25
26
static int     op_flags;
27
#define OPT_MOINS 0x1
28
#define OPT_s   0x2 
29
#define OPT_b   0x4 
30
31
#define DEFCOUNT 10
32
33
const char *hnames[] = {"Subject", "Content-type"};
34
int nh = sizeof(hnames) / sizeof(char *);
35
36
int main(int argc, char **argv)
37
{
38
    int count = DEFCOUNT;
39
    
40
    thisprog = argv[0];
41
    argc--; argv++;
42
43
    while (argc > 0 && **argv == '-') {
44
  (*argv)++;
45
  if (!(**argv))
46
      /* Cas du "adb - core" */
47
      Usage();
48
  while (**argv)
49
      switch (*(*argv)++) {
50
      case 's':   op_flags |= OPT_s; break;
51
      case 'b':   op_flags |= OPT_b; if (argc < 2)  Usage();
52
      if ((sscanf(*(++argv), "%d", &count)) != 1) 
53
          Usage(); 
54
      argc--; 
55
      goto b1;
56
      default: Usage();   break;
57
      }
58
    b1: argc--; argv++;
59
    }
60
61
    if (argc != 1)
62
  Usage();
63
64
    char *mfile = *argv++;argc--;
65
    int fd;
66
    if ((fd = open(mfile, 0)) < 0) {
67
  perror("Opening");
68
  exit(1);
69
    }
70
    Binc::MimeDocument doc;
71
    doc.parseFull(fd);
72
73
    if (!doc.isHeaderParsed() && !doc.isAllParsed()) {
74
  fprintf(stderr, "Parse error\n");
75
  exit(1);
76
    }
77
    close(fd);
78
    Binc::HeaderItem hi;
79
    for (int i = 0; i < nh ; i++) {
80
  if (!doc.h.getFirstHeader(hnames[i], hi)) {
81
      fprintf(stderr, "No %s\n", hnames[i]);
82
      exit(1);
83
  }
84
  printf("%s: %s\n", hnames[i], hi.getValue().c_str());
85
    }
86
    exit(0);
87
}