vpopmail 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -35,6 +35,63 @@ rmail subdirectory manually.
35
35
 
36
36
  To reach the author of ruby-vpopmail, send mail to gildas@breizh.org.
37
37
 
38
+ = Examples
39
+
40
+ == emailcheck
41
+
42
+ Just run ruby emailcheck email@address.com
43
+ and it will tell you if that email address is valid or not.
44
+
45
+ See ruby emailcheck --help for help.
46
+
47
+ == Incorporating emailcheck in maildrop's mailfilter
48
+
49
+ That's what I did in my own. Since I am not an expert at maildrop yet, I suspect there is a way to make this look nicer.
50
+
51
+ VCHKMAIL="/usr/bin/ruby /home/vpopmail/bin/emailcheck.rb"
52
+
53
+ ......
54
+
55
+ # Check if the sender exists
56
+ if ( $ISSPAM == 0)
57
+ {
58
+ ADDRESS=""
59
+ if ( /^Reply-To:\s+.*/ )
60
+ {
61
+ foreach (getaddr $MATCH) =~ /.+/
62
+ {
63
+ ADDRESS="$ADDRESS $MATCH"
64
+ }
65
+ }
66
+ else
67
+ if ( /^Return-Path:\s+.*/ )
68
+ {
69
+ foreach (getaddr $MATCH) =~ /.+/
70
+ {
71
+ ADDRESS="$ADDRESS $MATCH"
72
+ }
73
+ }
74
+ else
75
+ if ( /^From:\s+.*/ )
76
+ {
77
+ foreach (getaddr $MATCH) =~ /.+/
78
+ {
79
+ ADDRESS="$ADDRESS $MATCH"
80
+ }
81
+ }
82
+
83
+ if (length($ADDRESS) > 0)
84
+ {
85
+ log " Checking if Sender <$ADDRESS> is valid"
86
+ `$VCHKMAIL --silent --log -- $ADDRESS`
87
+ if ( $RETURNCODE == 1 )
88
+ {
89
+ log " Sender <$ADDRESS> does not exist"
90
+ ISSPAM=1
91
+ }
92
+ }
93
+ }
94
+
38
95
  = License
39
96
 
40
97
  Copyright (c) 2006 Gildas Cherruel
@@ -13,11 +13,14 @@ $APPNAME = File::basename(__FILE__, '.rb')
13
13
  $log = nil
14
14
  $VERBOSE = true
15
15
  $OPTS = GetoptLong.new(
16
- ["--domain", "-d", GetoptLong::REQUIRED_ARGUMENT],
17
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
18
- ["--log", GetoptLong::OPTIONAL_ARGUMENT],
19
- ["--silent", "-s", GetoptLong::NO_ARGUMENT],
20
- ["--verbose", "-v", GetoptLong::NO_ARGUMENT])
16
+ ["--blacklist", GetoptLong::REQUIRED_ARGUMENT],
17
+ ["--domain", "-d", GetoptLong::REQUIRED_ARGUMENT],
18
+ ["--whitelist", GetoptLong::REQUIRED_ARGUMENT],
19
+
20
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
21
+ ["--log", GetoptLong::OPTIONAL_ARGUMENT],
22
+ ["--silent", "-s", GetoptLong::NO_ARGUMENT],
23
+ ["--verbose", "-v", GetoptLong::NO_ARGUMENT])
21
24
 
22
25
  #------------------------------------------------------------------------------------------
23
26
  # function: Verbose {{{
@@ -65,18 +68,46 @@ def find_postmaster(p_domainname = nil)
65
68
  return "postmaster@#{p_domainname}"
66
69
  end # }}}
67
70
 
71
+ #------------------------------------------------------------------------------------------
72
+ # function: getlist {{{
73
+ def getlist(p_arg)
74
+ $log.info "Load list from #{p_arg}" if !$log.nil?
75
+ if p_arg =~ /^@(.*)/ then
76
+ $log.debug "list is a filename: #{$1}" if !$log.nil?
77
+ list = []
78
+ begin
79
+ IO.foreach($1) { |line|
80
+ next if line =~ /^\s*#/
81
+ next if line =~ /^\s*$/
82
+ list << line.strip
83
+ $log.debug "Added to the list: #{line}" if !$log.nil?
84
+ }
85
+ rescue Errno::ENOENT
86
+ Verbose "File: #{$1} does not exist"
87
+ end
88
+ return list
89
+ else
90
+ return p_arg.split(',')
91
+ end
92
+ end # }}}
93
+
68
94
  #------------------------------------------------------------------------------------------
69
95
  # main {{{
70
96
  domainname = nil
71
97
  logfile = nil
98
+ blacklist = []
99
+ whitelist = []
72
100
 
73
101
  $OPTS.each {|opt, arg| # {{{
74
102
  case opt
75
- when "--domain" then domainname = arg
76
- when "--help" then usage()
77
- when "--log" then logfile = arg.empty? ? "/var/log/qmail/#{$APPNAME}.log" : arg
78
- when "--silent" then $VERBOSE = false
79
- when "--verbose" then $VERBOSE = true
103
+ when "--blacklist" then blacklist = getlist(arg)
104
+ when "--domain" then domainname = arg
105
+ when "--whitelist" then whitelist = getlist(arg)
106
+
107
+ when "--help" then usage()
108
+ when "--log" then logfile = arg.empty? ? "/var/log/qmail/#{$APPNAME}.log" : arg
109
+ when "--silent" then $VERBOSE = false
110
+ when "--verbose" then $VERBOSE = true
80
111
  end
81
112
  } # }}}
82
113
 
@@ -93,7 +124,7 @@ if ARGV.size == 0 then
93
124
  exit 1
94
125
  end
95
126
  address = ARGV[0]
96
- valid = VPOPMail::Message.validAddress?(address, find_postmaster(domainname))
127
+ valid = VPOPMail::Message.validAddress?(address, find_postmaster(domainname), blacklist, whitelist)
97
128
  Verbose "Address #{address} is " + (valid ? "valid" : "invalid")
98
129
  exit valid ? 0 : 1
99
130
  # }}}
@@ -0,0 +1,54 @@
1
+ ISSPAM=0
2
+
3
+ # Check if the sender exists
4
+ if ( $ISSPAM == 0)
5
+ {
6
+ log " Fetching Sender"
7
+ ADDRESS=""
8
+ if ( /^Reply-To:\s+.*/ )
9
+ {
10
+ foreach (getaddr $MATCH) =~ /.+/
11
+ {
12
+ ADDRESS="$ADDRESS $MATCH"
13
+ }
14
+ log " Got Sender <$ADDRESS> from [Reply-To]"
15
+ }
16
+ else
17
+ if ( /^Return-Path:\s+.*/ )
18
+ {
19
+ foreach (getaddr $MATCH) =~ /.+/
20
+ {
21
+ ADDRESS="$ADDRESS $MATCH"
22
+ }
23
+ log " Got Sender <$ADDRESS> from [Return-Path]"
24
+ }
25
+ else
26
+ if ( /^From:\s+.*/ )
27
+ {
28
+ foreach (getaddr $MATCH) =~ /.+/
29
+ {
30
+ ADDRESS="$ADDRESS $MATCH"
31
+ }
32
+ log " Got Sender <$ADDRESS> from [From]"
33
+ }
34
+
35
+ if (length($ADDRESS) > 0)
36
+ {
37
+ log " Checking if Sender <$ADDRESS> is valid"
38
+ `/usr/bin/ruby /home/vpopmail/bin/emailcheck.rb --whitelist=@/home/vpopmail/etc/whitelist --blacklist=@/home/vpopmail/etc/blacklist --silent $ADDRESS`
39
+ log "Return code: $RETURNCODE"
40
+ if ( $RETURNCODE == 1 )
41
+ {
42
+ log " Sender <$ADDRESS> does not exist"
43
+ ISSPAM=1
44
+ }
45
+ else
46
+ {
47
+ log " Sender <$ADDRESS> does exist"
48
+ }
49
+ }
50
+ else
51
+ {
52
+ log " Weird, could not find any Sender"
53
+ }
54
+ }
@@ -3,7 +3,7 @@
3
3
  # Read COPYRIGHT in the root of VPOPMail library for copyright info
4
4
  # Creator: gildasc@rubyforg.org
5
5
  # Author: $Author: gildasc $
6
- # Version: $Id: vpopmail.rb 12 2006-10-09 08:49:52Z gildasc $
6
+ # Version: $Id: vpopmail.rb 13 2006-10-14 21:33:32Z gildasc $
7
7
  #++
8
8
 
9
9
  $:.unshift(File.dirname(__FILE__)) unless
@@ -27,8 +27,8 @@ module VPOPMail
27
27
  module VERSION #:nodoc:
28
28
  MAJOR = 1
29
29
  MINOR = 0
30
- TINY = 1
31
- BUILD = %q$Id: vpopmail.rb 12 2006-10-09 08:49:52Z gildasc $
30
+ TINY = 2
31
+ BUILD = %q$Id: vpopmail.rb 13 2006-10-14 21:33:32Z gildasc $
32
32
  STRING = [MAJOR, MINOR, TINY].join('.')
33
33
  end # }}}
34
34
 
@@ -3,7 +3,7 @@
3
3
  # Read COPYRIGHT in the root of VPOPMail library for copyright info
4
4
  # Creator: gildasc@rubyforg.org
5
5
  # Author: $Author: gildasc $
6
- # Version: $Id: message.rb 9 2006-10-09 01:12:10Z gildasc $
6
+ # Version: $Id: message.rb 14 2006-10-14 22:17:39Z gildasc $
7
7
  #++
8
8
 
9
9
  require 'rexml/document'
@@ -109,13 +109,35 @@ class Message
109
109
  # MX Servers. Then it will use the SMTP protocol to query the MX servers for the validity
110
110
  # of <tt>p_address</tt>
111
111
  #
112
+ # <tt>p_blackList</tt> contains the list of email address or domains that should always
113
+ # be rejected.
114
+ # <tt>p_whiteList</tt> contains the list of email address or domains that should always
115
+ # be accepted.
116
+ #
112
117
  # === Possible Exceptions
113
118
  # * SMTPServerBusy
114
- def self.validAddress?(p_address, p_local)
119
+ def self.validAddress?(p_address, p_local, p_blacklist = [], p_whitelist = [])
115
120
  p_address = RMail::Address.parse(p_address)[0] if !p_address.kind_of? RMail::Address
116
121
  p_local = RMail::Address.parse(p_local)[0] if !p_local.kind_of? RMail::Address
117
122
 
118
123
  logger.info "Checking Domain: #{p_address.domain}" if !@@logger.nil?
124
+
125
+ if p_blacklist.include?(p_address.address)
126
+ logger.info "Address #{p_address.address} is in the blacklist"
127
+ return false
128
+ end
129
+ if p_blacklist.include?(p_address.domain)
130
+ logger.info "Domain #{p_address.domain} is in the blacklist"
131
+ return false
132
+ end
133
+ if p_whitelist.include?(p_address.address)
134
+ logger.info "Address #{p_address.address} is in the whitelist"
135
+ return true
136
+ end
137
+ if p_whitelist.include?(p_address.domain)
138
+ logger.info "Domain #{p_address.domain} is in the whitelist"
139
+ return true
140
+ end
119
141
  begin
120
142
  resolver = Net::DNS::Resolver.new
121
143
  answer = resolver.query(p_address.domain, Net::DNS::MX)
@@ -163,9 +185,14 @@ class Message
163
185
  # the origin email address when querying the mail server of <tt>p_address</tt>
164
186
  # from the current Message
165
187
  #
188
+ # <tt>p_blackList</tt> contains the list of email address or domains that should always
189
+ # be rejected.
190
+ # <tt>p_whiteList</tt> contains the list of email address or domains that should always
191
+ # be accepted.
192
+ #
166
193
  # See Message.validAddress?
167
- def validAddress?(p_address)
168
- return Message.validAddress?(p_address, @folder.domain.postmaster)
194
+ def validAddress?(p_address, p_blacklist = [], p_whitelist = [])
195
+ return Message.validAddress?(p_address, @folder.domain.postmaster, p_blacklist, p_whitelist)
169
196
  end # }}}
170
197
 
171
198
  #--------------------------------------------------------------------------------------
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: vpopmail
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2006-10-09
6
+ version: 1.0.2
7
+ date: 2006-10-15
8
8
  summary: Ruby VPOPMail interface
9
9
  require_paths:
10
10
  - lib
@@ -37,6 +37,7 @@ files:
37
37
  - lib/vpopmail/message.rb
38
38
  - lib/vpopmail/user.rb
39
39
  - examples/emailcheck.rb
40
+ - examples/mailfilter
40
41
  - examples/vdelfakemail.rb
41
42
  - examples/vlearn.rb
42
43
  - Rakefile