~ubuntu-branches/ubuntu/hardy/dbacl/hardy

« back to all changes in this revision

Viewing changes to src/hmine.c

  • Committer: Bazaar Package Importer
  • Author(s): Zak B. Elep
  • Date: 2006-03-26 22:35:35 UTC
  • mto: (2.1.1 etch) (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060326223535-icwiulpkzesds4mq
ImportĀ upstreamĀ versionĀ 1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 
64
64
int exit_code = 0; /* default */
65
65
 
 
66
 
66
67
/***********************************************************
67
68
 * FUNNY FUNCTIONS                                         *
68
69
 ***********************************************************/
 
70
void print_mailbox(hline_t *h, char *buf, int buflen) {
 
71
  char *p = NULL;
 
72
  char *q = NULL;
 
73
  parse_2822_mls_t *mls = NULL;
 
74
  parse_2822_mbx_t *mbx = NULL;
 
75
  parse_2822_als_t *als = NULL;
 
76
  switch(h->tag) {
 
77
  case hltFRM: 
 
78
    p = "from"; 
 
79
    mls = &h->data.frm.rfc2822;
 
80
    break;
 
81
  case hltRFR: 
 
82
    p = "resend-from"; 
 
83
    mls = &h->data.rfr.rfc2822;
 
84
    break;
 
85
  case hltRPT: 
 
86
    p = "reply-to"; 
 
87
    als = &h->data.rpt.rfc2822;
 
88
    break;
 
89
  case hltRRT: 
 
90
    p = "resend-reply-to"; 
 
91
    als = &h->data.rrt.rfc2822;
 
92
    break;
 
93
  case hltSND: 
 
94
    p = "sender"; 
 
95
    mbx = &h->data.snd.rfc2822;
 
96
    break;
 
97
  case hltRSN: 
 
98
    p = "resend-sender"; 
 
99
    mbx = &h->data.rsn.rfc2822;
 
100
    break;
 
101
  case hltTO:  
 
102
    p = "to"; 
 
103
    als = &h->data.to.rfc2822;
 
104
    break;
 
105
  case hltRTO: 
 
106
    p = "resend-to"; 
 
107
    als = &h->data.rto.rfc2822;
 
108
    break;
 
109
  case hltCC:  
 
110
    p = "cc"; 
 
111
    als = &h->data.cc.rfc2822;
 
112
    break;
 
113
  case hltRCC: 
 
114
    p = "resend-cc"; 
 
115
    als = &h->data.rcc.rfc2822;
 
116
    break;
 
117
  case hltBCC: 
 
118
    p = "bcc"; 
 
119
    als = &h->data.bcc.rfc2822;
 
120
    break;
 
121
  case hltRBC: 
 
122
    p = "resend-bcc"; 
 
123
    als = &h->data.rbc.rfc2822;
 
124
    break;
 
125
  default:  
 
126
    /* nothing */
 
127
    break;
 
128
  }
 
129
  if( p && !(h->state & (1<<H_STATE_BAD_DATA)) ) {
 
130
    if( mls ) {
 
131
      q = unfold_token(buf, buflen, mls->mailboxl_.begin, mls->mailboxl_.end, ',');
 
132
      while( q ) {
 
133
        bracketize_mailbox(buf, buflen);
 
134
        fprintf(stdout, "%s %s\n", p, buf);
 
135
        if( q >= mls->mailboxl_.end ) { break; }
 
136
        q = unfold_token(buf, buflen, q, mls->mailboxl_.end, ',');
 
137
      }
 
138
    } else if( als ) {
 
139
      q = unfold_token(buf, buflen, als->addressl_.begin, als->addressl_.end, ',');
 
140
      while( q ) {
 
141
        bracketize_mailbox(buf, buflen);
 
142
        fprintf(stdout, "%s %s\n", p, buf);
 
143
        if( q >= als->addressl_.end ) { break; }
 
144
        q = unfold_token(buf, buflen, q, als->addressl_.end, ',');
 
145
      }
 
146
    } else if( mbx ) {
 
147
      q = unfold_token(buf, buflen, mbx->mailbox_.begin, mbx->mailbox_.end, ',');
 
148
      bracketize_mailbox(buf, buflen);
 
149
      fprintf(stdout, "%s %s\n", p, buf); 
 
150
    }
 
151
  }
 
152
}
 
153
 
69
154
void print_summary() {
70
 
/*   int i; */
 
155
  int i;
 
156
  char buf[1024];
71
157
/*   time_t numsec = (time_t)-1; */
72
158
/*   for(i = 0; i < head.hstack.top; i++) { */
73
159
/*     if( head.hstack.hlines[i].tag == hltRCV ) { */
84
170
/*   } */
85
171
/*   printf("\n"); */
86
172
 
87
 
  printf("I have nothing to say.\n");
88
 
 
 
173
  if( u_options & (1<<U_OPTION_HM_ADDRESSES) ) {
 
174
    /* we print out any mailboxes we find, preceded by type */
 
175
    for(i = 0; i < head.hstack.top; i++) {
 
176
      print_mailbox(head.hstack.hlines + i, buf, 1024);
 
177
    }
 
178
  }
89
179
}
90
180
 
91
181
/***********************************************************
96
186
  fprintf(stderr, 
97
187
          "\n");
98
188
  fprintf(stderr, 
99
 
          "hmine [-vD] [FILE]\n");
 
189
          "hmine [-vDa] [FILE]\n");
100
190
  fprintf(stderr, 
101
191
          "\n");
102
192
  fprintf(stderr, 
114
204
int hset_option(int op, char *optarg) {
115
205
  int c = 0;
116
206
  switch(op) {
 
207
  case 'a':
 
208
    u_options |= (1<<U_OPTION_HM_ADDRESSES);
 
209
    break;
117
210
  case 'D':
118
211
    u_options |= (1<<U_OPTION_DEBUG);
119
212
    break;
208
301
 
209
302
  /* parse the options */
210
303
  while( (op = getopt(argc, argv, 
211
 
                      "vVD")) > -1 ) {
 
304
                      "aDvV")) > -1 ) {
212
305
    hset_option(op, optarg);
213
306
  }
214
307
 
225
318
     or if none provided read stdin */
226
319
  if( (optind > -1) && *(argv + optind) ) {
227
320
    /* if it's a filename, process it */
228
 
    input = fopen(argv[optind], "r");
 
321
    input = fopen(argv[optind], "rb");
229
322
    if( input ) {
230
323
      inputfile = argv[optind];
231
324
 
251
344
 
252
345
  }
253
346
  /* in case no files were specified, get input from stdin */
254
 
  if( !(u_options & (1<<U_OPTION_STDIN)) ) {
 
347
  if( !(u_options & (1<<U_OPTION_STDIN)) &&
 
348
      (input = fdopen(fileno(stdin), "rb")) ) {
255
349
 
256
350
    if( (u_options & (1<<U_OPTION_VERBOSE)) && 
257
351
        !(u_options & (1<<U_OPTION_CLASSIFY)) ) {
258
352
      fprintf(stdout, "taking input from stdin\n");
259
353
    }
260
354
 
261
 
    hprocess_file(stdin, &head);
 
355
    hprocess_file(input, &head);
262
356
 
263
357
    /* must close before freeing in_iobuf, in case setvbuf was called */
264
 
    fclose(stdin); 
 
358
    fclose(input); 
265
359
 
266
360
  }
267
361