-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepEmailToSend0.1.pl
190 lines (165 loc) · 5.7 KB
/
prepEmailToSend0.1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/perl
#
#sendEmailSMTPStandard.pl
#
#This looks sends out an email
#
#
#Args = ARGV[0]:emailaddress
#Args = ARGV[1]:sms value
#Args = ARGV[2]:from email
#
#
#
#important variables in this script
my $from= $global_email_Main_User_Name;
my $subject='';
my $title='Perl Mail demo';
#
#
use strict;
my $portToAddToString;
if ($global_pop3_Port) {
$portToAddToString = $global_pop3_Port;
}
else {
$portToAddToString = "25";
}
open (LOG, ">>logs\/log_sendEmailSMTP.txt");
print LOG "#######\n#######\n####Next Email\n######\n#####\n#####\n";
#arg1 is phone number of sender
#arg2 is text
my $toEmail = $ARGV[0];
chomp($toEmail);
print LOG "the toEmail is <$toEmail>\n";
my $theText = $ARGV[1];
chomp($theText);
$theText =~ s/</</g;
$theText =~ s/>/>/g;
$theText =~ s/\\n/\n/g;
$theText =~ s/45454545454545/\n/g; #some posts use this number to make carriage returns
$theText =~ s/\n /\n /g;
$theText =~ s/ / /g;
print LOG "theText is <$theText>\n";
$from = $ARGV[2];
chomp($from);
$from =~ ~ s/\\n/\n/g;
if ($theText =~ /^$/) {
print LOG "there was no text to send out so we will die now\n";
close LOG;
die;
}
my ($sec, $min, $hr, $day, $mon, $year) = localtime;
printf LOG ("#\n#\n#\n%02d/%02d/%04d %02d:%02d:%02d:In sendEmailSMTP with:$toEmail\n#and theText:\n$theText\n#\n", $day, $mon + 1, 1900 + $year, $hr, $min, $sec);
my @attachmentArray;
lookforAttachments();
my $tempScalar = scalar(@attachmentArray);
if ($tempScalar) {
print LOG "This is the first attachment $attachmentArray[0]\n";
}
print LOG "there are this many attachments <$tempScalar>\n";
$_ = $theText;
print LOG "the email before switching out attachments <\n\n$theText\n\n>\n";
$theText =~ s/ 789502735 .* 789502735 //g;
chomp($theText);
$theText =~ s/\n+$//g;
$theText =~ s/\r+$//g;
$theText =~ s/\s+$//g;
print LOG "the email now states after attachments and lagging white space are gone \n\n<\n$theText\n>\n\n";
makeToEmailBeMMSIfAttachmentsOr140Char();
my $to=$toEmail;
my $tempVal = 0;
my $attachmentString = "";
my $isAttachment = 0;
while (<@attachmentArray>) {
if ($_ =~ /\w/) {
if ($tempVal == 0) {
$isAttachment = 1;
$attachmentString = "-a \""
}
$attachmentString = $attachmentString . "email\/attachments\/$attachmentArray[$tempVal] ";
}
$tempVal++;
}
if ($isAttachment) {
$attachmentString =~ /^(.+) $/;
$attachmentString = $1 . '"';
}
my $toSystem;
$theText = $theText . "\n";
#$theText =~ s/\n/\n<br><p>\p/g;
#$theText = "\"" . $theText . "\"";
open (TXT, ">\/var\/mangojane\/message.txt");
print TXT $theText;
close TXT;
my $htmlString = "";
my $needsToBeHTML = 0;
if (length($theText>160) and $attachmentString =~ /^$/) {
$needsToBeHTML = 1;
}
#while (length($theText) > 0 ) {
#$toSystem = "python sendEmailOnly0.2.py -f $from -t $to -of /var/mangojane/message.txt -server $global_email_url -p $portToAddToString -xu $from -xp $global_email_Mail_User_Password -ot tls=no -omch message-charset=utf-8 -html $needsToBeHTML $attachmentString";
#python sendEmailOnly0.2.py -f [email protected] -t [email protected] -of /var/mangojane/message.txt -server localhost
$toSystem = "python sendEmailOnly0.2.py -f $from -t $to -of /var/mangojane/message.txt -server $global_email_url -xu $global_email_Main_User_Name -xp $global_email_Mail_User_Password $attachmentString";
#if (length($theText>160) and $attachmentString =~ /^$/) {
# $theText = substr $theText, 160, (length($theText)-160);
# $attachmentString = 0;
#}
#else {
# $theText = "";
#}
#}
#system("sendEmail -f $from -t $to -u \"Database Dump\" -m \"$theText\" -s sambatop.com:2525 -xu $fromEmail -xp 1qazZAQ! -o tls=no -o message-content-type=html $attachmentString");
chomp($toSystem);
$toSystem =~ s/\n+$//g;
$toSystem =~ s/\r+$//g;
$toSystem =~ s/\s+$//g;
print LOG "about to send out to system:<$toSystem>";
system("$toSystem");
close(MAIL);
close(LOG);
sub lookforAttachments {
print LOG "\tIn lookforAttachments\n";
my $myText = $theText;
my $myInt = 0;
while ($myText =~ /789502735/) {
print LOG "\twhile loop turn $myInt with myText: \n\t#\n\t<$myText>\n\t#\n";
my $first;
my $rest;
my $theAttachment;
($first, $theAttachment, $rest) = split(/789502735/, $myText, 3);
$theAttachment =~ /^\s*(\S+)\s*$/;
my $filtered = $1;
print LOG "\t\tthe attachmentment found was <$filtered>\n";
$attachmentArray[$myInt] = $filtered;
$myText = $rest;
$myInt += 1;
}
}
sub makeToEmailBeMMSIfAttachmentsOr140Char {
use DBI;
my $host = $global_MYSQL_host;
my $database = $global_MYSQL_database;
my $username = $global_MYSQL_username;
my $password = $global_MYSQL_password;
#all of the blog variables
my $connectionInfo = "dbi:mysql:$database;$host";
my $connection = DBI->connect($connectionInfo, $username, $password);
print LOG "in makeToEmailBeMMSIfAttachmentsOr140Char with toEmail \n\n<\n$toEmail\n>\n\n";
my $mytempScalar = scalar(@attachmentArray);
print LOG "there are this many attachments <$mytempScalar>\n";
if (($mytempScalar > 0) or (length($theText) > 140)) {
print LOG "we believe there is an attachment so we will try to change the email address\n";
$toEmail =~ m/^(.*)(@.*)$/i;
my $sid = $1;
my $domain = $2;
print LOG "looking at this attachment and we have sid=<$sid> and domain=<$domain>\n";
my $str = $connection->prepare("SELECT mmsDomain FROM sms2mmsEmails WHERE (smsDomain = \'$domain\')");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if (@resultsCheck) {
$toEmail = $sid . $resultsCheck[0];
}
}
print LOG "leaving makeToEmailBeMMSIfAttachmentsOr140Char with toEmail=<$toEmail>\n";
}