[tarent-useful-scripts SCM] git branch master updated. 6e46fcc44bee12f59e6fa121fc6cb08a71ddad03

mirabilos at evolvis.org mirabilos at evolvis.org
Wed May 21 15:02:31 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main git repository for Evolvis project useful-scripts".

The branch, master has been updated
       via  6e46fcc44bee12f59e6fa121fc6cb08a71ddad03 (commit)
       via  c85fc895c9ccac04db0fbb8c31052e66252fabb5 (commit)
      from  ec3a1f2e5f4d8c2b9ea19e0f3c70cebf137dfdaa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6e46fcc44bee12f59e6fa121fc6cb08a71ddad03
Author: Thorsten Glaser <t.glaser at tarent.de>
Date:   Wed May 21 15:02:10 2014 +0200

    add tool to convert "foo=bar, blah=baz" string to dictionary

commit c85fc895c9ccac04db0fbb8c31052e66252fabb5
Author: Thorsten Glaser <t.glaser at tarent.de>
Date:   Wed May 21 15:00:59 2014 +0200

    add script to find eMail addresses in text

-----------------------------------------------------------------------

Summary of changes:
 findmail/findmail.pl |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/str2dict.py     |   21 ++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 findmail/findmail.pl
 create mode 100644 misc/str2dict.py

diff --git a/findmail/findmail.pl b/findmail/findmail.pl
new file mode 100644
index 0000000..eb6b15f
--- /dev/null
+++ b/findmail/findmail.pl
@@ -0,0 +1,67 @@
+# $Id: findmail.pl 824 2010-01-15 13:28:47Z tglase $
+#-
+# Copyright © 2009
+#	Thorsten Glaser <t.glaser at tarent.de>
+# All rights reserved.
+#-
+# Derived from Email::Find 0.10
+#
+# Copyright 2000, 2001 Michael G Schwern <schwern at pobox.com>.
+# All rights reserved.
+#
+# Current maintainer is Tatsuhiko Miyagawa <miyagawa at bulknews.net>.
+#
+# This module is free software; you may redistribute it and/or modify it
+# under the same terms as Perl itself.
+
+use strict;
+
+# Need qr//.
+require 5.005;
+
+# This is the BNF from RFC 822
+my $esc         = '\\\\';
+my $period      = '\.';
+my $space       = '\040';
+my $open_br     = '\[';
+my $close_br    = '\]';
+my $nonASCII    = '\x80-\xff';
+my $ctrl        = '\000-\037';
+my $cr_list     = '\n\015';
+my $qtext       = qq/[^$esc$nonASCII$cr_list\"]/; #"
+my $dtext       = qq/[^$esc$nonASCII$cr_list$open_br$close_br]/;
+my $quoted_pair = qq<$esc>.qq<[^$nonASCII]>;
+my $atom_char   = qq/[^($space)<>\@,;:\".$esc$open_br$close_br$ctrl$nonASCII]/; #"
+my $atom        = qq<$atom_char+(?!$atom_char)>;
+my $quoted_str  = qq<\"$qtext*(?:$quoted_pair$qtext*)*\">; #"
+my $word        = qq<(?:$atom|$quoted_str)>;
+my $local_part  = qq<$word(?:$period$word)*>;
+
+# This is a combination of the domain name BNF from RFC 1035 plus the
+# domain literal definition from RFC 822, but allowing domains starting
+# with numbers.
+my $label       = q/[A-Za-z\d](?:[A-Za-z\d-]*[A-Za-z\d])?/;
+my $domain_ref  = qq<$label(?:$period$label)*>;
+my $domain_lit  = qq<$open_br(?:$dtext|$quoted_pair)*$close_br>;
+my $domain      = qq<(?:$domain_ref|$domain_lit)>;
+
+# Finally, the address-spec regex (more or less)
+my $Addr_spec_re   = qr<$local_part\s*\@\s*$domain>;
+
+sub matched {
+	my $orig_match = $1;
+	my $end_cruft = '';
+	if( $orig_match =~ s|([),.'";?!]+)$|| ) { #"')){
+		$end_cruft = $1;
+	}
+	print $orig_match."\n";
+	$end_cruft;
+}
+
+while (<>) {
+    my $r_text = $_;
+
+    $r_text =~ s{($Addr_spec_re)}{
+	matched($1);
+    }eg;
+}
diff --git a/misc/str2dict.py b/misc/str2dict.py
new file mode 100644
index 0000000..3616c3d
--- /dev/null
+++ b/misc/str2dict.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# coding: utf-8
+# $Id: tools.py 660 2009-10-01 09:17:51Z tglase $
+#-
+# Copyright © 2009
+#   Thorsten Glaser <t.glaser at tarent.de>
+
+__version__ = """
+    $Id: tools.py 660 2009-10-01 09:17:51Z tglase $
+"""
+
+def str2dict(s):
+    """Convert a "foo=bar, blah=baz" type string into a dictionary"""
+
+    if type(s) not in (str, unicode):
+        s = str(s)
+    d = {}
+    for kv in [[x.strip() for x in i.split('=', 1)] for i in s.split(',')]:
+        if (len(kv[0]) > 0) and (len(kv[1]) > 0):
+            d[kv[0]] = kv[1]
+    return d


hooks/post-receive
-- 
Main git repository for Evolvis project useful-scripts
(Evolvis project useful-scripts repository useful-scripts)


More information about the Useful-scripts-commits mailing list