Re: compose.php and HTML5's registerProtocolHandler
"Michael A. Puls II" <[email protected]>
| Newsgroups | gmane.mail.squirrelmail.devel |
|---|---|
| Message-ID | <op.unj11wmj1ejg13@sandra-svwliu01> |
On Sun, 04 Jan 2009 08:33:08 -0500, Michael A. Puls II <[email protected]> wrote: > I know that compose.php supports > ?send_to=&subject=&body=&send_to_cc=&send_to_bcc= > > However, is there support for doing it the following way? > > http://squirrelmail_server.com/src/compose.php?url=mailto%3Ato%2540example.com%3Fsubject%3Dtest%2520subject%26body%3Dline1%250D%250Aline2%26cc%3Dcc%2540example.com%26bcc%3Dbcc%2540example.com I see there's "mailto.php?emailaddress=", but it doesn't handle complicated mailto URI data very well or to my liking. > The reason I ask is that HTML5's registerProtocolHandler supports %s in > its template string, which emits the data like that. > This is also how Firefox 3 makes "tools -> options -> applications -> > mailto -> Use gmail" work. > > For example with "https://mail.google.com/mail/?extsrc=mailto&url=%s" > and a mailto URI of > "mailto:to%40example.com?subject=test%20subject&body=line1%0D%0Aline2&cc=cc%40example.com&bcc=bcc%40example.com", > you'd get > "https://mail.google.com/mail/?extsrc=mailto&url=mailto%3Ato%2540example.com%3Fsubject%3Dtest%2520subject%26body%3Dline1%250D%250Aline2%26cc%3Dcc%2540example.com%26bcc%3Dbcc%2540example.com", > which if you test, works great. > > <https://developer.mozilla.org/en/DOM/window.navigator.registerProtocolHandler> > <http://www.whatwg.org/specs/web-apps/current-work/#dom-navigator-registerprotocolhandler> > > If SM does not support this, is there any plan to? > > Thanks > 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 Thanks On a side, when I have a signature set, SM inserts a blank line at the top of the body. How can I remove that? -- 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 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');
$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);
$hvalue = rawurlencode($hvalue);
if ($hname === "to") {
if (strlen($hvalue) !== 0) {
if (strlen($to) !== 0) {
$to .= "%2C%20";
}
$to .= preg_replace("/%0D|%0A/i", "", $hvalue);
}
} else if ($hname === "cc") {
if (strlen($hvalue) !== 0) {
if (strlen($cc) !== 0) {
$cc .= "%2C%20";
}
$cc .= preg_replace("/%0D|%0A/i", "", $hvalue);
}
} else if ($hname === "bcc") {
if (strlen($hvalue) !== 0) {
if (strlen($bcc) !== 0) {
$bcc .= "%2C%20";
}
$bcc .= preg_replace("/%0D|%0A/i", "", $hvalue);
}
} else if ($hname === "subject") {
$subject = preg_replace("/%0D|%0A/i", "", $hvalue);
} else if ($hname === "body") {
if (!(strlen($body) === 0 and strlen($hvalue) === 0)) {
if (strlen($body) !== 0) {
$body .= "%0D%0A";
}
$body .= $hvalue;
}
}
}
}
}
}
}
sqsession_is_active();
$compose = "send_to=";
$compose .= $to;
$compose .= '&subject=';
$compose .= $subject;
$compose .= '&body=';
$compose .= $body;
$compose .= '&send_to_cc=';
$compose .= $cc;
$compose .= '&send_to_bcc=';
$compose .= $bcc;
$redirect = "compose.php?" . $compose;
session_write_close();
header('Location: ' . get_location() . '/' . $redirect);