ScalixMailGoogleGadget

From Scalix Wiki
Jump to: navigation, search

Scalix Wiki -> How-Tos -> ScalixMailGoogleGadget -> ScalixMailGoogleGadget.php


Copy/paste the code below in a text editor and save the file with .php extension (for example ScalixMailGoogleGadget.php) Modify the three fields ($user, $password, $url) at the beginning of this file

<?php

/*
 * test_http.php
 *
 * @(#) $Header: /home/mlemos/cvsroot/http/test_http.php,v 1.14 2004/12/09 00:53:48 mlemos Exp $
 *
 */

?>
<?php
	require("http.php");
	require("sasl.php");
	
	// Modify the three fields below...
	$user="";
	$password="";
	$url=""; //http://<myscalix.org>/api/<mailbox@myscalix.com>/mailbox/INBOX/?output=rss
	// replace <myscalix.org>  and <mailbox@myscalix.com> according to your settings

	set_time_limit(0);
	$http=new http_class;

	/* Connection timeout */
	$http->timeout=0;

	/* Data transfer timeout */
	$http->data_timeout=0;

	/* Output debugging information about the progress of the connection */
	$http->debug=0;

	/* Format dubug output to display with HTML pages */
	$http->html_debug=0;


	/*
	 *  Need to emulate a certain browser user agent?
	 *  Set the user agent this way:
	 */
	//$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

	/*
	 *  If you want to the class to follow the URL of redirect responses
	 *  set this variable to 1.
	 */
	$http->follow_redirect=1;

	/*
	 *  How many consecutive redirected requests the class should follow.
	 */
	$http->redirection_limit=5;

	/*
	 *  If your DNS always resolves non-existing domains to a default IP
	 *  address to force the redirection to a given page, specify the
	 *  default IP address in this variable to make the class handle it
	 *  as when domain resolution fails.
	 */
	$http->exclude_address="";

	/*
	 *  If basic authentication is required, specify the user name and
	 *  password in these variables.
	 */
	$base64=base64_encode($user.":".$password);
	
	
	/*
	 *  Generate a list of arguments for opening a connection and make an
	 *  HTTP request from a given URL.
	 */
	$error=$http->GetRequestArguments($url,$arguments);

	if(strlen($realm))
		$arguments["AuthRealm"]=$realm;

	if(strlen($workstation))
		$arguments["AuthWorkstation"]=$workstation;

	$http->authentication_mechanism=""; // force a given authentication mechanism;

	/*
	 *  If you need to access a site using a proxy server, use these
	 *  arguments to set the proxy host and authentication credentials if
	 *  necessary.
	 */
	/*
	$arguments["ProxyHostName"]="127.0.0.1";
	$arguments["ProxyHostPort"]=3128;
	$arguments["ProxyUser"]="proxyuser";
	$arguments["ProxyPassword"]="proxypassword";
	$arguments["ProxyRealm"]="proxyrealm";  // Proxy authentication realm or domain
	$arguments["ProxyWorkstation"]="proxyrealm"; // Workstation for NTLM proxy authentication
	$http->proxy_authentication_mechanism=""; // force a given proxy authentication mechanism;
	*/

	/* Set additional request headers */
	$arguments["Headers"]["Pragma"]="nocache";
	
	// Do basic authentication
	$arguments["Headers"]["Authorization"]="Basic ".$base64;
/*
	Is it necessary to specify a certificate to access a page via SSL?
	Specify the certificate file this way.
	$arguments["SSLCertificateFile"]="my_certificate_file.pem";
	$arguments["SSLCertificatePassword"]="some certificate password";
*/

/*
	Is it necessary to preset some cookies?
	Just use the SetCookie function to set each cookie this way:

	$cookie_name="LAST_LANG";
	$cookie_value="de";
	$cookie_expires="2010-01-01 00:00:00"; // "" for session cookies
	$cookie_uri_path="/";
	$cookie_domain=".php.net";
	$cookie_secure=0; // 1 for SSL only cookies
	$http->SetCookie($cookie_name, $cookie_value, $cookie_expiry, $cookie_uri_path, $cookie_domain, $cookie_secure);
*/

	$error=$http->Open($arguments);

	if($error=="")
	{

		$error=$http->SendRequest($arguments);

		if($error=="")
		{

			$headers=array();
			$error=$http->ReadReplyHeaders($headers);
			if($error=="")
			{
				switch($http->response_status)
				{
					case "301":
					case "302":
					case "303":
					case "307":
						echo " (redirect to <TT>".$headers["location"]."</TT>)<BR>\nSet the <TT>follow_redirect</TT> variable to handle redirect responses automatically.";
						break;
				}

				for(;;)
				{
					$error=$http->ReadReplyBody($body,1000);
					if($error!=""
					|| strlen($body)==0)
						break;
					echo $body;
				}
				flush();
			}
		}
		$http->Close();
	}
	if(strlen($error))
		//echo "<CENTER><H2>Error: ",$error,"</H2><CENTER>\n";
?>