Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. To: John and Julie <john@example.com>, John and Julie <julie@example.com>, Bobby and Liz <bobby@example.net>, Kevin and Jayme <kevin3248@example.com>, Kevin and Jayme <jayme8396@example.com>, Ellen and Mike <mike397987@example.com>, Ellen and Mike <ellen397286@example.com>,
  2.  
  3. >,
  4.  
  5. #!/usr/bin/perl
  6.  
  7. use strict;
  8. use warnings FATAL => 'all';
  9.  
  10. use EmailConfig;
  11. use File::Slurp;
  12.  
  13. # Turn off output buffering
  14. $| = 1;
  15.  
  16. my @emailConfig = ();
  17.  
  18. sub main() {
  19. loadConfig();
  20. processDataAndSendEmail();
  21. }
  22.  
  23. main();
  24.  
  25. sub loadConfig() {
  26.  
  27. my @raw_configs = read_file('email_config.txt');
  28.  
  29. foreach my $raw_config ( @raw_configs ) {
  30.  
  31. my $newEmailConfig = new EmailConfig();
  32. $newEmailConfig->init($raw_config);
  33. push @emailConfig, $newEmailConfig;
  34. }
  35. }
  36.  
  37. sub processDataAndSendEmail() {
  38.  
  39. my $to = '';
  40.  
  41. foreach my $config ( @emailConfig ) {
  42.  
  43. foreach my $email ( @{ $config->{emails} } ) {
  44.  
  45. print "$emailn";
  46. $to .= "$config->{name} <$email>, ";
  47. }
  48. }
  49.  
  50. print "To: $to";
  51. }
  52.  
  53. package EmailConfig;
  54.  
  55. use strict;
  56. use warnings FATAL => 'all';
  57.  
  58. my $emailConfigRegex = qr/(?<email_name>.*) = (?<email_addresses>.*)/;
  59.  
  60. sub new {
  61. my $class = shift;
  62. my $self = {};
  63. bless $self, $class;
  64. return $self;
  65. }
  66.  
  67. sub init {
  68. my $self = shift;
  69.  
  70. my $emailConfigValue = shift;
  71.  
  72. if ($emailConfigValue =~ $emailConfigRegex) {
  73. $self->{name} = $+{email_name};
  74. @{$self->{emails}} = split(';', $+{email_addresses});
  75. }
  76.  
  77. my $print_emails = join(",", @{$self->{emails}});
  78. print "EmailConfig initialized: $self->{name} = $print_emailsn";
  79. }
  80.  
  81. 1;
  82.  
  83. John and Julie = john@example.com;julie@example.com
  84. Bobby and Liz = bobby@example.net
  85. Kevin and Jayme = kevin3248@example.com;jayme8396@example.com
  86. Ellen and Mike = mike397987@example.com;ellen397286@example.com
  87.  
  88. sub init {
  89. ...
  90. $+{email_addresses}=~s/r//g;
  91. @{$self->{emails}} = split(';', $+{email_addresses});
  92. ...
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement