Re: compose.php and HTML5's registerProtocolHandler
"Michael A. Puls II" <[email protected]>
| Newsgroups | gmane.mail.squirrelmail.devel |
|---|---|
| Message-ID | <op.unlrumpq1ejg13@sandra-svwliu01> |
On Sat, 10 Jan 2009 14:07:15 -0500, Michael A. Puls II <[email protected]> wrote: > Attached is mailto_protocol_handler2.php. I used mailto.php as a > reference. > > It produces the exact results I want it to. There are just 2 problems. > > 1. How do I load compose.php in the right frame AND get compose.php to > use ?send_to=&body= etc. like it does when not loaded in a frame? > > 2. When the user is not logged in, I want to redirect to login.php and > retain the send_to=&body= etc. data after the user logs in. > > mailto.php does these things, but it uses ?mailtodata=, which uses some > funky data format that's percent-encoded, which compose.php decodes etc. > > How do I make things work with "send_to=" etc. or how to I convert the > to, cc, bcc, body and subject percent-encoded hvalues that I've built > into something that ?mailtodata= understands? > > If you look at mailto.php, I basically want to support the > !$compose_only and $force_login features. > > I'm doing this with 1.4.x I figured it out. ?mailtodata= just wants a percent-encoded serialized array of the to, cc, bcc, subject and body values(decoded). Attached is with everything working. It works much better with the mailto link at <http://shadow2531.com/opera/testcases/mailto/modern_mailto_uri_scheme.html#test> than mailto.php does. -- Michael ------------------------------------------------------------------------------ Check out the new SourceForge.net Marketplace. It is the best place to buy or sell services for just about anything Open Source. http://p.sf.net/sfu/Xq1LFB ----- squirrelmail-devel mailing list Posting guidelines: http://squirrelmail.org/postingguidelines List address: [email protected] List archives: http://news.gmane.org/gmane.mail.squirrelmail.devel List info (subscribe/unsubscribe/change options): https://lists.sourceforge.net/lists/listinfo/squirrelmail-devel
mailto_protocol_handler2.php
(application/octet-stream, 4.4 KB)
<?php
/**
* mailto_protocol_handler2.php
*
* This page accepts a percent-encoded mailto URI (via ?uri=) that was
* generated by HTML5's registerProtocolHandler and converts the data
* into the format that compose.php?send_to=&subject=&body=&cc=&bcc=
* requires to fill in the compose form's fields.
*
* <https://developer.mozilla.org/en/DOM/window.navigator.registerProtocolHandler>
* <http://www.whatwg.org/specs/web-apps/current-work/#dom-navigator-registerprotocolhandler>
*
* This handler takes duplicate hvalues in the mailto URI and joins
* them according to the following rules.
*
* to, cc and bcc: Join all non-empty hvalues with %2C%20.
*
* subject: Use only the last subject hvalue, even if it's empty.
*
* body: Join the first non-empty hvalue and all hvalues after that
* (even if they're empty) with %0D%0A.
*
* Unsafe %HH like %00 in the mailto URI are percent-encoded so they
* come out literally in the field.
*
* Newlines are removed from the to, cc, bcc and subject hvalues
*
*/
/** This is the mailto_protcol_handler page */
define('PAGE_NAME', 'mailto_protocol_handler2');
/**
* Path for SquirrelMail required files.
* @ignore
*/
define('SM_PATH', '../');
/* SquirrelMail required files. */
require_once(SM_PATH . 'functions/global.php');
// Force users to login each time
$force_login = FALSE;
// Open only the compose window, meaningless if $force_login is TRUE
$compose_only = FALSE;
header('Pragma: no-cache');
$to = "";
$subject = "";
$body = "";
$cc = "";
$bcc = "";
if (sqgetGlobalVar('uri', $mailtoURI)) {
if (stristr($mailtoURI, 'mailto:')) {
$dataset = "to=" . preg_replace("/\\?/", "&", substr($mailtoURI, 7), 1);
$keys = explode("&", $dataset);
foreach ($keys as $i) {
if (strlen($i) > 1) {
$eq = strpos($i, '=');
if ($eq !== false) {
$hname = strtolower(rawurldecode(substr($i, 0, $eq)));
$hvalue = rawurldecode(substr($i, $eq + 1));
$hvalue = preg_replace_callback("/[\\x00-\\x08]|[\\x0B-\\x0C]|[\\x0E-\\x1F]/", create_function('$match', 'return rawurlencode($match[0]);'), $hvalue);
$hvalue = preg_replace("/\r\n|\r|\n/", "\r\n", $hvalue);
if ($hname === 'to') {
if (strlen($hvalue) !== 0) {
if (strlen($to) !== 0) {
$to .= ', ';
}
$to .= preg_replace("/\\r|\\n/", "", $hvalue);
}
} else if ($hname === 'cc') {
if (strlen($hvalue) !== 0) {
if (strlen($cc) !== 0) {
$cc .= ', ';
}
$cc .= preg_replace("/\\r|\\n/", "", $hvalue);
}
} else if ($hname === 'bcc') {
if (strlen($hvalue) !== 0) {
if (strlen($bcc) !== 0) {
$bcc .= ', ';
}
$bcc .= preg_replace("/\\r|\\n/", "", $hvalue);
}
} else if ($hname === 'subject') {
$subject = preg_replace("/\\r|\\n/", "", $hvalue);
} else if ($hname === 'body') {
if (!(strlen($body) === 0 and strlen($hvalue) === 0)) {
if (strlen($body) !== 0) {
$body .= "\r\n";
}
$body .= $hvalue;
}
}
}
}
}
}
}
sqsession_is_active();
// Create an array so it can be serialized for ?mailtodata=
$data = array();
$data['to'] = $to;
$data['subject'] = $subject;
$data['body'] = $body;
$data['cc'] = $cc;
$data['bcc'] = $bcc;
if (!$force_login && sqsession_is_registered('user_is_logged_in')) {
if ($compose_only) {
$redirect = 'compose.php?mailtodata=' . urlencode(serialize($data));
} else {
$redirect = 'webmail.php?right_frame=compose.php&mailtodata=' . urlencode(serialize($data));
}
} else {
$redirect = 'login.php?mailtodata=' . urlencode(serialize($data));
}
session_write_close();
header('Location: ' . get_location() . '/' . $redirect);