for user to: - add email mapping - delete email mapping - re-map email mapping - search email mapping from stdin or map file or - delete email mapping queue
Usage: email_mapping -n name [-e email_address] [-d] [-s] [-r] email_mapping -f mapping_file [-r] [-d] email_mapping --delete-queue
options: -n, --name name|email|tag appoint a name|email|tag to add mapping -e, --email email_address appoint a email to be mapped -f, --file filename appoint a mapping file for name/email -r, --re-map do re-mappings -d, --delete delete email mappings --delete-queue delete mapping queue -s, --search search email mapping -h, --help show this message
the name can be either a name, an email or something like a tag. the file content consists of names and emails, like:
name: email_address_d tag: email_address_d email_address_r: email_address_d
can map multi name|tag|email_address to a single email address
Signed-off-by: Luan Shengde shdluan@163.com --- sbin/email-mapping.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/sbin/email-mapping.rb b/sbin/email-mapping.rb index 9d72ecc..d3a9a62 100755 --- a/sbin/email-mapping.rb +++ b/sbin/email-mapping.rb @@ -9,7 +9,8 @@ require 'optparse' REDIS_HOST = 'localhost' REDIS_PORT = '6379'
-require "#{ENV['CCI_SRC']}/lib/email_mapping_client" +# require_relative "#{ENV['CCI_SRC']}/lib/redis_client" +require '../lib/redis_client'
r_name = nil d_email = nil @@ -74,17 +75,22 @@ end options.parse!(ARGV)
def email_mapping(r_name, d_email, map_conf) - email_mapping = EmailMapping.new(r_name, d_email) + email_mapping = RedisClient.new('email_mapping') if map_conf['re_mapping'] - email_mapping.re_map_email + email_mapping.reset_hash_key(r_name, d_email) elsif map_conf['del_map'] - email_mapping.delete_email_mapping + email_mapping.delete_hash_key(r_name) elsif map_conf['search_map'] - puts email_mapping.search_map + mapped_email = email_mapping.search_hash_key(r_name) + if mapped_email.nil? || mapped_email.empty? + puts "#{r_name} has not been mapped an email yet." + else + puts mapped_email + end elsif map_conf['delete_queue'] - email_mapping.delete_mapping_queue + email_mapping.delete_queue else - return if email_mapping.add_email_mapping + return if email_mapping.add_hash_key(r_name, d_email)
puts "#{r_name} has already mapped an email." end