postfix_status_line 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94a439a7c52803281aed989326452482635a1a51
4
- data.tar.gz: 879309fe801021f6ca9405d3f999b3787f1a0626
3
+ metadata.gz: ba1d3cc388e6481f1a89bae81c03f0964e2edac3
4
+ data.tar.gz: 2aeacc192ab96a747017c8befeef4609e8be0896
5
5
  SHA512:
6
- metadata.gz: 92907958f1605d908366b9d032f8a8b98ded4175f5b6dfdc35dd5f08f0829b2df2586d76d2e5fa50c4e8e2d8fcf0d9815294e6f0733dda30ab5f28ada1ee7cfd
7
- data.tar.gz: c58b95c85fe2b700e4c69027cb5c99205db1e8dda75a02a992dfabb1b049ce5428f271f4dd52e82e6e5819f5cc4401610496516960a96846cbbb16e1544be5be
6
+ metadata.gz: ea847a0a7d39284df8f02f94e41575d5561495367b48fd9c767e434504067d5b540d248ad935da826dc088eccb04e3e4561f6217d7e3263c1af5bfa47fc5813e
7
+ data.tar.gz: 2797537e8eb181261ea00bfc6ecf535633a89f1bf4f5e6af440b2885b413c4a3c99f33830657f641d749126db82cacfdd07bde614c0141e5e1226819f40bc989
data/README.md CHANGED
@@ -63,9 +63,7 @@ PostfixStatusLine.parse(status_line, hash: true, sha_algorithm: 256)
63
63
  PostfixStatusLine.parse(status_line, parse_time: true)
64
64
  ```
65
65
 
66
- ### Parse Header Checks Warning
67
-
68
- see http://www.postfix.org/header_checks.5.html
66
+ ### Parse [header_checks](http://www.postfix.org/header_checks.5.html)
69
67
 
70
68
  ```ruby
71
69
  warning = "Mar 4 14:44:19 P788 postfix/cleanup[7426]: E80A9DF6F7E: warning: header Subject: test from local; from=<sugawara@P788.local> to=<sgwr_dts@yahoo.co.jp>"
@@ -79,7 +77,8 @@ PostfixStatusLine.parse_header_checks_warning(warning)
79
77
  # "to"=>"********@yahoo.co.jp",
80
78
  # "domain"=>"yahoo.co.jp",
81
79
  # "from"=>"********@P788.local",
82
- # "Subject"=>"test from local;"
80
+ # "header_from"=>"local",
81
+ # "Subject"=>"test"
83
82
  # }
84
83
  ```
85
84
 
@@ -273,18 +273,45 @@ static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, cha
273
273
  }
274
274
  }
275
275
 
276
- static void put_header(char *str, VALUE hash, bool mask) {
277
- if (strncmp(str, "warning: header ", 16) != 0) {
276
+ static void put_header(char *str, size_t len, VALUE hash, bool mask) {
277
+ if (str[len - 1] != ';') {
278
278
  return;
279
279
  }
280
280
 
281
- str += 16;
282
- char *value = strchr(str, ':');
281
+ char *without_cmd = strchr(str, ':');
282
+
283
+ if (without_cmd == NULL) {
284
+ return;
285
+ }
286
+
287
+ if (strncmp(without_cmd, ": header ", 9) != 0) {
288
+ return;
289
+ }
290
+
291
+ char *value = strchr(without_cmd + 9, ':');
283
292
 
284
293
  if (value == NULL || *(value + 1) == '\0') {
285
294
  return;
286
295
  }
287
296
 
297
+ *without_cmd = '\0';
298
+ without_cmd += 9;
299
+
300
+ int i;
301
+
302
+ for (i = (int) len - 2; i >= 0; i--) {
303
+ if (str[i] == ' ') {
304
+ char *chunk = str + i + 1;
305
+
306
+ if (strncmp(chunk, "from ", 5) == 0) {
307
+ str[len - 1] = '\0';
308
+ rb_hash_aset(hash, rb_str_new2("header_from"), rb_str_new2(chunk + 5));
309
+ str[i] = '\0';
310
+ break;
311
+ }
312
+ }
313
+ }
314
+
288
315
  if (mask) {
289
316
  mask_email(value);
290
317
  }
@@ -292,9 +319,8 @@ static void put_header(char *str, VALUE hash, bool mask) {
292
319
  *value = '\0';
293
320
  value += 2;
294
321
 
295
- VALUE v_key = rb_str_new2(str);
296
- VALUE v_value = rb_str_new2(value);
297
- rb_hash_aset(hash, v_key, v_value);
322
+ rb_hash_aset(hash, rb_str_new2("priority"), rb_str_new2(str));
323
+ rb_hash_aset(hash, rb_str_new2(without_cmd), rb_str_new2(value));
298
324
  }
299
325
 
300
326
  static void split_line3(char *str, bool mask, VALUE hash, bool include_hash, char *salt, size_t salt_len, DIGEST_SHA digest_sha_func) {
@@ -312,7 +338,7 @@ static void split_line3(char *str, bool mask, VALUE hash, bool include_hash, cha
312
338
  } else if (strncmp(chunk, "from=", 5) == 0) {
313
339
  put_attr(chunk, hash, mask, include_hash, salt, salt_len, digest_sha_func);
314
340
  ptr[i] = '\0';
315
- put_header(ptr, hash, mask);
341
+ put_header(ptr, i, hash, mask);
316
342
  break;
317
343
  }
318
344
  }
@@ -483,7 +509,7 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask,
483
509
  return hash;
484
510
  }
485
511
 
486
- static VALUE rb_postfix_status_line_parse_header_checks_warning(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time, VALUE v_sha_algo) {
512
+ static VALUE rb_postfix_status_line_parse_header_checks(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time, VALUE v_sha_algo) {
487
513
  char *str;
488
514
  size_t len;
489
515
  bool mask;
@@ -517,5 +543,5 @@ void Init_postfix_status_line_core() {
517
543
  VALUE rb_mPostfixStatusLine = rb_define_module("PostfixStatusLine");
518
544
  VALUE rb_mPostfixStatusLineCore = rb_define_module_under(rb_mPostfixStatusLine, "Core");
519
545
  rb_define_module_function(rb_mPostfixStatusLineCore, "parse", rb_postfix_status_line_parse, 6);
520
- rb_define_module_function(rb_mPostfixStatusLineCore, "parse_header_checks_warning", rb_postfix_status_line_parse_header_checks_warning, 6);
546
+ rb_define_module_function(rb_mPostfixStatusLineCore, "parse_header_checks", rb_postfix_status_line_parse_header_checks, 6);
521
547
  }
@@ -14,13 +14,13 @@ module PostfixStatusLine
14
14
  end
15
15
  module_function :parse
16
16
 
17
- def parse_header_checks_warning(str, options = {})
17
+ def parse_header_checks(str, options = {})
18
18
  mask = options.has_key?(:mask) ? options[:mask] : true
19
19
  hash = options[:hash]
20
20
  salt = options[:salt]
21
21
  parse_time = options[:parse_time]
22
22
  sha_algo = options[:sha_algorithm]
23
- PostfixStatusLine::Core.parse_header_checks_warning(str, mask, hash, salt, parse_time, sha_algo)
23
+ PostfixStatusLine::Core.parse_header_checks(str, mask, hash, salt, parse_time, sha_algo)
24
24
  end
25
- module_function :parse_header_checks_warning
25
+ module_function :parse_header_checks
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module PostfixStatusLine
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postfix_status_line
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler