Promote your online product free of charge on Craigslist!
Post ReplyPromote your online product free of charge on Craigslist!Posted: Saturday, July 31, 2021 [14:54:30] - 1
Perl script to capture SMS messagesPosted: Saturday, July 31, 2021 [15:01:42] - 2
Our weapon of choice is Perl. The same could be done in PHP, Python languages. You mileage may vary. use strict; use warnings; $ENV{'PATH'} = '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'; my $localtime = `date`; my $dateu=time; my $client=''; my $dir='/Your_Program_Folder'; ## Replace fields below with information to fit your account my $gmail_name='Joe Smith '; my $just_user='your_user_account'; my $username = '[email protected]'; my $password = 'your_gmail_password'; my $keepfor=180; # DAYS ## Personal data end my $removemes = $dateu - (86400 * $keepfor); open(STDOUT,">$dir/last.result.txt"); use Mail::IMAPClient; use IO::Socket::SSL; use MIME::Base64 (); my $sock = IO::Socket::SSL->new( PeerAddr => "imap.gmail.com", PeerPort => 993) or die $@; $client = Mail::IMAPClient->new( Socket => $sock, User => $username, Password => $password ); my $folders = $client->folders or die "List folders error: ", $client->LastError, "\n"; print "Folders: @$folders\n"; $client->select('INBOX') or die "Select 'INBOX' error: ", $client->LastError, "\n"; our %pbsearch=(); our %donecalls=(); our %replies=(); my @messages = $client->messages; @messages = reverse @messages; foreach my $bs (@messages){ my $from = $client->get_header($bs,"from"); unless($from =~ m/txt\.voice\.google\.com/i) {$x--; my $date = $client->get_header($bs,"date"); my $subj = $client->get_header($bs,"subject"); my $message = $client->body_string( $bs ); my($mtext,$dtstamp,$toph,$frph,$clcode) = readmess($message,$date,$from); if($donecalls{$recdtime}) {print "DONE already\t$from\t$date\n"; my $visphone=''; if(length($frph) == 11) { $visphone=$frph; $donecalls{$recdtime}{phone_from}=$visphone; } $numberofcalls++; $donecalls{$recdtime}{from}=$frph; $donecalls{$recdtime}{from_email}=$from; $donecalls{$recdtime}{to}=$toph; $donecalls{$recdtime}{phonestamp}=$clcode; $donecalls{$recdtime}{message}=$mtext; $donecalls{$recdtime}{date}=$date; $donecalls{$recdtime}{udate}=$dateu; $donecalls{$recdtime}{subject}=$subj; print "From: $from\nDate: $date\nSubject: $subj\nStamp: $dtstamp\nTo: $toph\nFrom Ph: $frph\nCode: $clcode\nMessage: $mtext\n\n"; if($pbsearch{$frph}) {$donecalls{$recdtime}{name}=$pbsearch{$frph}; my $response=''; foreach my $k (keys(%replies)) { if($mtext =~ m/\Q$k\E/i || $k =~ m/\Q$mtext\E/i) {$response = $replies{$k}; } ## FOREACH REPLY END if($response) {print "---- Response required ----\n\n"; print "From: $donecalls{$recdtime}{from_email}\nResponse: $response\n"; $respond{$donecalls{$recdtime}{from_email}}{response}=$response; $respond{$donecalls{$recdtime}{from_email}}{subject}=$donecalls{$recdtime}{subject}; $donecalls{$recdtime}{responded}=$response; } ## END RESPONSE REQUIRED } ## FOR END $client->logout(); print "\nFinished login\nNumber of calls: $numberofcalls\n\n"; if($numberofcalls > 0) { print "Number of calls received: $numberofcalls\n"; open(TXC,">$dir/done.calls.txt"); foreach my $t (sort keys(%donecalls)) { if($donecalls{$t}{udate} < $removemes) {next;} ## REMOVE OLD MESSAGES print TXC "$comma'$t' => {\n"; foreach my $k (sort keys %{$donecalls{$t}}) {$donecalls{$t}{$k} =~ s/\'/\\\'/g; print TXC "$comma1'$k','$donecalls{$t}{$k}'"; } ## FOREACH KEY END print TXC "\n\t}"; } ## FOREACH TIMESTAMP END print TXC "\n);\n"; } ## END NEW CALLS FOUND my $noresp = keys(%respond); print "Number of responses: $noresp\n"; if($noresp > 0) { print "\nSENDING RESPONSE\n"; use MIME::Entity; use Net::SMTP; use IO::Socket::SSL; use Authen::SASL; foreach my $to (keys (%respond)) { my $subject = $respond{$to}{subject}; my $message = $respond{$to}{response}; print "Response Subject: $subject\nMessage: $message\n\n"; my $from = "$gmail_name<$username>"; my $mime = MIME::Entity->build(Type => 'multipart/alternative', Encoding => '-SUGGEST', From => $from, To => $to, Subject => $subject ); $mime->attach(Type => 'text/plain', Encoding =>'-SUGGEST', Data => $message); my $errors=''; my $smtp = Net::SMTP->new('smtp.gmail.com', Port => 465, SSL => 1, Hello => "$just_user.local", Timeout => 20 ); if($@) {print "ERROR: $@\n\n"; my $sasl = Authen::SASL->new( mechanism => 'GSSAPI', callback => { pass => $password, user => $username, } ); eval {$smtp->auth( $sasl )}; if($@) {print "Authentication error: $@\n"; if($errors) {$smtp->quit(); $smtp->mail($from); $smtp->to($to); $smtp->data($mime->stringify); $smtp->quit(); } ## FOREACH TO EMAIL END } ## END RESPOND TO SMS sub readmess { my ($m,$date,$from) = @_; my $spl = shift(@ms); my @parts = split(/$spl/,$m); shift(@parts); $m =~ s#(.*?)\<(.*?)\>(.*)#$3#s; if($m =~ m/text\/plain/ && $m =~ m/base64/) { $m =~ s#(.*?)(base64)(.*)#$3#s; $m =~ s#(.*?)\<(.*?)\>(.*)#$3#s; } ## END IF BASE64 my $notags = $m =~ s#<(.*?)>#$g; if($notags > 10) {$m='';} $m =~ s#(.*?)(YOUR ACCOUNT|To respond to this text message)(.*)#$1#s; $m =~ s/^\s+//; #Sat, 19 Sep 2020 16:54:15 +0000 $date =~ s/\,//g; $date =~ s# #\.#g; $from =~ s#(.*?)<(.*)>#$2#; $from =~ s#(\d{11})\.(\d+)\.(.*?)(\@)(.*)##; my $phfr=$2; return ($m,$date,$phto,$phfr,$code); } # END SUB READ MESSAGE sub doerrors { my $err = shift; my $sendmail = '/usr/sbin/sendmail -t -oi'; open(MAIL,"|$sendmail"); print MAIL <<EOM; From: user\@domain.com To: user_rcv\@domain.com Subject: Eval Error found using Gmail SMS reply \nWhile trying to send email VIA Gmail procedure error was found! Reported by: check.gmail.cgi Error: $err EOM close(MAIL); exit(0);} ## END SUB DO ERRORS Next - replies.txt file content. |
Replies.txt file contentPosted: Saturday, July 31, 2021 [15:09:39] - 3
For script to properly respond to different Craigslist ads keywords based on Ad content used in "replies.txt" file. For example: 'book','Books for sale: https://www.Your_Site.com/for-sale/books/', 'chevrole','2005 Chevy Camaro for sale: https://www.Your_Site.com/camaro-for-sale/', 'directio','Direction to us: https://www.google.com/maps/dir//1.0602554,-5.2755837/@1.0602543,-5.2761792,19z/data=!2f7!4k1!1z9', 'genera','12000W generator for sale: https://www.Your_Site.com/generator/' ); Do not forget to test your program by sending SMS-es with keywords. |
Running script from CronPosted: Saturday, July 31, 2021 [15:25:08] - 4
SMS script has to be run periodically. It could be every 1 minute or every 5 minutes. Easiest way to run it probably is a cron job by adding the line to /etc/crontab i.e.: it will run your program every 5 minutes. |