Important alert: (current site time 7/15/2013 9:35:32 PM EDT)
 

VB icon

Send an Message to an ICQ account without ICQ!

Email
Submitted on: 11/11/2000 8:56:18 PM
By: Brandon McPherson 
Level: Intermediate
User Rating: By 6 Users
Compatibility: 5.0 (all versions)
Views: 20753
author picture
(About the author)
 
     I found this code on the web(source forgotten - my bad), and made minimal changes to it. This allows you to send a message to an ICQ Account.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Send an Message to an ICQ account without ICQ!
= Description:I found this code on the web(source forgotten - my bad), and made minimal changes to it. This allows you to send a message to an ICQ Account.
= By: Brandon McPherson
=
= Inputs:It's all self-contained.
=
= Returns:HTML
=
= Side Effects:Excessive hair growth :)
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=142&lngWId=6=for details.=**************************************

#!/usr/bin/perl
my $TITLE = "Page me on ICQ!";
my $BGCOLOR = "#FFCC00";
my $TEXT_COLOR_NORMAL = "#000000";
my $REQUIRED_TEXT_COLOR = "Black";
my $BACKGROUND_URL = "";
my $CGI_DIR = "http://www.servername.com/cgi-bin";
$SHOW_OPTIONAL_FIELDS = 0;
my $sendmail = "/usr/sbin/sendmail";
my $destination_email = "1234567\@pager.icq.com";
&print_header;
&get_form_data;
if (!$FORM_DATA{'mail'}) {
&print_html_form;
} else {
$error = 0;
&check_form_data;
if (!$error) {
&send_mail;
&reply_to_user;
}
}
exit(0);
sub print_header {
print ("Content-type: text/html\n\n");
print ("<HTML>\n<HEAD>\n<TITLE>$TITLE</TITLE>\n</HEAD>\n");
print ("<BODY BGCOLOR=\"$BGCOLOR\" BACKGROUND=\"$BACKGROUND_URL\" ");
print ("TEXT=\"$TEXT_COLOR_NORMAL\">\n");
}#print_header
sub get_form_data {
$request_method = $ENV{'REQUEST_METHOD'};
if ($request_method eq "GET") {
	$form_info = $ENV{'QUERY_STRING'};
} else {
	$size_of_form_information = $ENV{'CONTENT_LENGTH'};
	read (STDIN, $form_info, $size_of_form_information);
}
@key_value_pairs = split (/&/, $form_info);
foreach $key_value (@key_value_pairs) {
	($key, $value) = split (/=/, $key_value);
	$value =~ tr/+/ /;
	$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
	if (defined($FORM_DATA{$key})) {
		$FORM_DATA{$key} = join (", ", $FORM_DATA{$key}, $value);
	} else {
		$FORM_DATA{$key} = $value;
	}
}
} #get_form_data
sub print_html_form {
print <<__END_OF_HTML_CODE__;
<FORM ACTION="$CGI_DIR/icq.pl" METHOD="POST">
<INPUT TYPE="hidden" NAME="to" VALUE="$FORM_DATA{'to'}">
__END_OF_HTML_CODE__
if ($SHOW_OPTIONAL_FIELDS) {
print ("<BR><FONT COLOR=\"$REQUIRED_TEXT_COLOR\"><B>All required ");
print ("information is bolded in this color.</B></FONT>\n");
print ("Everything else is just for my own curiosity. <BR>");
}
print <<__END_OF_HTML_CODE__;
<TABLE BORDER="0" CELLPADDING="4" CELLSPACING="2">
<TR VALIGN="top">
<TD>
<TABLE>
__END_OF_HTML_CODE__
if ($SHOW_OPTIONAL_FIELDS) {
print ("<TR VALIGN=\"top\">\n");
print ("<TD>Your name:</TD>\n");
print ("<TD><INPUT TYPE=\"text\" NAME=\"users_name\"></TD>\n");
print ("</TR>\n");
}
print <<__END_OF_HTML_CODE__; 
<TR VALIGN="top">
<TD><FONT COLOR="$REQUIRED_TEXT_COLOR"><B>Your email:</B></FONT></TD>
<TD><INPUT TYPE="text" NAME="users_email">
<FONT COLOR="$REQUIRED_TEXT_COLOR">
</TD>
</TR>
</TABLE>
<BR>
__END_OF_HTML_CODE__
if ($SHOW_OPTIONAL_FIELDS) {
print <<__END_OF_HTML_CODE__;
	<TABLE>
	<TR VALIGN="top">
	<TD>Your country of residence:</TD>
	<TD><INPUT TYPE="text" NAME="users_country"><BR><BR></TD>
	</TR>
	<TR VALIGN="top">
	<TD>Your home State/Province:</TD>
	<TD>
	<INPUT TYPE="radio" NAME="state_usa" VALUE="USA">
	If inside the U.S.:
	<SELECT NAME="state_address1" SIZE="1">
	<OPTION>Alabama
	<OPTION>Alaska
	<OPTION>Arizona
	<OPTION>Arkansas
	<OPTION>Hawaii
	<OPTION>California
	<OPTION>Colorado
	<OPTION>Connecticut
	<OPTION>Delaware
	<OPTION>Florida
	<OPTION>Georgia
	<OPTION>Idaho
	<OPTION>Illinois
	<OPTION>Indiana
	<OPTION>Iowa
	<OPTION>Kansas
	<OPTION>Kentucky
	<OPTION>Louisiana
	<OPTION>Maine
	<OPTION>Maryland
	<OPTION>Massachusetts
	<OPTION>Michigan
	<OPTION>Minnesota
	<OPTION>Mississippi
	<OPTION>Missouri
	<OPTION>Montana
	<OPTION>Nebraska
	<OPTION>Nevada
	<OPTION>New Hampshire
	<OPTION>New Jersey
	<OPTION>New Mexico
	<OPTION>New York
	<OPTION>North Carolina
	<OPTION>North Dakota
	<OPTION>Ohio
	<OPTION>Oklahoma
	<OPTION>Oregon
	<OPTION>Pennsylvania
	<OPTION>Rhode Island
	<OPTION>South Carolina
	<OPTION>South Dakota
	<OPTION>Tennessee
	<OPTION>Texas
	<OPTION>Utah
	<OPTION>Vermont
	<OPTION>Virginia
	<OPTION>Washington
	<OPTION>Washington, D.C.
	<OPTION>West Virginia
	<OPTION>Wisconsin
	<OPTION>Wyoming
	</SELECT><BR>
	<INPUT TYPE="radio" NAME="state_usa" VALUE="NOT_USA">
	If outside the U.S.:
	<INPUT TYPE="text" NAME="state_address2">
	</TD>
	</TR>
	</TABLE>
	<BR>
__END_OF_HTML_CODE__
}
print <<__END_OF_HTML_CODE__;
<FONT COLOR="$REQUIRED_TEXT_COLOR"><B>Please enter your message
below:</B></FONT><BR>
<TEXTAREA NAME="message" ROWS="8" COLS="40"></TEXTAREA>
<BR>
Please note that your are limited to 450 characters.
<BR>
<BR>
<INPUT TYPE="hidden" NAME="mail" VALUE="1">
<INPUT TYPE="submit" VALUE="$TITLE">
</TD>
</TR>
</TABLE>
<BR>
</FORM>
</BODY>
</HTML>
__END_OF_HTML_CODE__
} #print_html_form
sub check_form_data {
my %error_codes = (
"1" => "You need to enter your email address.",
"2" => "You seemed to have forgotten to enter the
email message you wish to send.",
"3" =>"For security reasons, you cannot have any of the following characters in your email or subject fields: [ ; < > & \* ` \| ] "
);
if ($FORM_DATA{'users_email'} !~ /\@/ && 
	$FORM_DATA{'users_email'} !~ /\w/) {
	$error = 1;
} elsif ($FORM_DATA{'message'} !~ /\w/) {
	$error = 2;
}
if (($FORM_DATA{"subject"} =~ /[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/) || ($FORM_DATA{"to"} =~ /[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/)
	|| ($FORM_DATA{"users_email"} =~ /[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/)) {
	$error = 3;
}
if ($error) {
	print ("<H3>\n");
	print ("D'OH!<br>");
	print ("We had a little mishap. This is why:<BR> \n");
	print ("<BR>$error_codes{$error}\n<BR>\n<BR>");
	print ("Please hit the back button in your browser to ");
	print ("correct this. Thank you!\n");
	print ("</H3>\n</BODY>\n</HTML>\n");
}
if ($FORM_DATA{'to'} ne "") {
	$destination_email = $FORM_DATA{'to'};
}
} #check_form_data
sub send_mail {
open (MESSAGE, "| $sendmail -t -oi ");
print MESSAGE <<__END_OF_MESSAGE__;
To: $destination_email
From: $FORM_DATA{"users_email"}
__END_OF_MESSAGE__
if ($FORM_DATA{'users_name'} ne "") {
	print MESSAGE ("$FORM_DATA{'users_name'} - ");
}
print MESSAGE ("$FORM_DATA{'users_email'} paged you on ICQ ");
print MESSAGE ("from your website.\n");
if ($FORM_DATA{'users_country'} ne "") {
	print MESSAGE ("They are in the country of: $FORM_DATA{'users_country'}\n");
}
if ($FORM_DATA{'state_usa'} =~ /^USA$/i) {
	print MESSAGE ("They are writing from the state of: $FORM_DATA{'state_address1'}\n\n");
} elsif ($FORM_DATA{'state_usa'} =~ /^NOT_USA$/i) {
	print MESSAGE ("They are writing from the province of: $FORM_DATA{'state_address2'}\n\n");
}
print MESSAGE ("The follow is what they had to say:\n\n");
print MESSAGE ("$FORM_DATA{'message'}\n");
close (MESSAGE);
if ($FORM_DATA{'keep_copy'}) {
	open (MESSAGE, "| $sendmail -t -oi ");
	print MESSAGE <<__END_OF_MESSAGE__;
To: $FORM_DATA{"users_email"}
__END_OF_MESSAGE__
print MESSAGE ("The following is what you wrote from the ");
	print MESSAGE ("$TITLE webpage...:\n\n");
print MESSAGE ("$FORM_DATA{'message'}\n");
close (MESSAGE);
}
} #send_mail
sub reply_to_user {
print ("Thank you for paging me on ICQ<BR><BR>\n");
print ("Below is a copy of the information you sent me:<BR>\n");
print ("<DL>\n");
if ($FORM_DATA{'users_name'} ne "") {
	print ("<DT><B>Your name:</B>\n<DD>$FORM_DATA{'users_name'}<BR><BR>\n");
}
print ("<DT><B>Your email:</B>\n<DD>$FORM_DATA{'users_email'}<BR><BR>\n"); 
if ($FORM_DATA{'users_country'} ne "") {
	print ("<DT><B>Your country:</B>\n<DD>$FORM_DATA{'users_country'}<BR><BR>\n");
}
if ($FORM_DATA{'state_address1'} ne "" && $FORM_DATA{'state_usa'} =~ /^USA$/i) {
	print ("<DT><B>Your state:</B>\n<DD>$FORM_DATA{'state_address1'}<BR><BR>\n"); 
} elsif ($FORM_DATA{'state_address2'} ne "" && $FORM_DATA{'state_usa'} =~ /^NOT_USA$/i) { 
	print ("<DT><B>Your state:</B>\n<DD>$FORM_DATA{'state_address2'}<BR><BR>\n") if ($FORM_DATA{'state_address2'} ne "");
}
print ("<DT><B>Your message:</B>\n<DD>$FORM_DATA{'message'}<BR><BR>\n");
print ("</DL>\n");
print ("</BODY>\n</HTML>\n");
} #reply_to_user
#FILE: icq.pl


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
11/12/2000 4:51:56 PMBrandon McPherson

Please vote if you like this code.

We need some activity here on this side of the site!
(If this comment was disrespectful, please report it.)

 
11/23/2000 1:06:24 PMaSerb

Hi, I'm a newbie in CGI I have no idea on how to make this work. I have alot of friends that have ICQ and this would be cool to have on my web site but I can't get it to work. I have changed the www.servername.com to my web site URL and i have saved the copy-paste to a file name: icq.cgi and icq.pl and it doesn't work I also tryed to change the CHMOD to all "777" but nothing works. I dont't visit this side of the site alot i'm ussualy on the VB side of planet-source-code so plz. email me (aserb@aserb.com) a .zip with a readme.txt explaining how to make this work. if not plz. upload it on planet-source-code.com (.Zip) Thanks alot.
(If this comment was disrespectful, please report it.)

 
12/26/2000 8:30:28 PMnato_

hay.. what if your server doesn't have the sendmail program on it?.. could you do it w/ CDontsMail?.. and if so.. just how?
(If this comment was disrespectful, please report it.)

 
12/29/2000 2:54:13 AMJeff_TM@hotmail.com

sorry newbies... you need an acount that supports telnet first, then the sendmail option. And there are many different reasons you can't get the code to work. for one, it sounds like your trying to call the cgi from an html page. That is what you want to do, but you have to set up a form as well. And if there is no form set up, then it will give you errors. Try this: put all the cgi in your cgi-bin, chmod them to 755, and call them from a web page. If you get something like "internal error", then at least you can call it. The last thing to do would to get the form on the html page done.
(If this comment was disrespectful, please report it.)

 
3/8/2001 7:02:48 AMFlanders

also it wont work if your server doesnt support cgi
(If this comment was disrespectful, please report it.)

 
5/15/2001 4:15:36 AMThushan Fernando

So there goes every1s idea for using GeoCities for doing this... or is it yahoo geocities now?? Ohhh well u know what i mean!
(If this comment was disrespectful, please report it.)

 
3/16/2002 12:06:23 PMDraz

I expected some more from this script.. like direct UDP communications or something like that.. Still it looks okay to me..
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.