Can an iCal attachment contain HTML in the description property? If so, what are the restrictions?
After doing some research and testing. The answer is a qualified no. Meaning: you could throw it in there, but you shouldn't.
It is not strictly forbidden by the RFC, but DESCRIPTION is not the appropriate property for HTML content.
DESCRIPTION should be the plain text version of your content. The property X-ALT-DESC with a FMTTYPE declaration of text/html is the appropriate property for HTML content.
The following example worked in both Outlook and Gmail/Google Calendar, but does not appear to be supported by Thunderbird(w/Lightning): (please, forgive the ouput. it was generated by Outlook)
X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//E
N">\n<HTML>\n<HEAD>\n<META NAME="Generator" CONTENT="MS Exchange Server ve
rsion 08.00.0681.000">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!-- Converted f
rom text/rtf format -->\n\n<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG
="en-us"><FONT FACE="Calibri">Is this in HTML?</FONT></SPAN><SPAN LANG="en
-us"></SPAN><SPAN LANG="en-us"></SPAN></P>\n\n<P DIR=LTR><SPAN LANG="en-us
"><FONT FACE="Calibri">Bullets:</FONT></SPAN></P>\n\n<P DIR=LTR><SPAN LANG
="en-us"><FONT FACE="Calibri">1. \; \; \; \; \;</FONT>
</SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-
us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"> <FONT FACE="Calib
ri">Test 1</FONT></SPAN></P>\n\n<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="
Calibri">2. \; \; \; \; \;</FONT></SPAN><SPAN LANG="en
-us"> <FONT FACE="Calibri">Test 2</FONT></SPAN><SPAN LANG="en-us"></SPAN><
SPAN LANG="en-us"></SPAN></P>\n\n<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPA
N LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>\n\n</BODY>\n</HTML>
Like any HTML rendering in an email client supported tags and styles are limited.
HTML in the description won't be rendered as HTML in Outlook, at the least. If you want to include rich text that Outlook will recognize, export an event from your Outlook calendar, and take a look at what they do. I believe they provide plain-text in the Description and then create another property for the HTML.
For anyone happening upon this page like I did and is looking to specifically have HTML content displayed for Outlook events...
As the accepted answer states, the DESCRIPTION shouldn't have any HTML. However, you can get HTML into the content of the event (at least in Outlook) using a multipart/alternative email.
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="_CAL_B598a1969806776.58663423_B_"
To: "Your Name" <yourname#example.com>
From: "John Doe" <john.doe#example.com>
--_CAL_B598a1969806776.58663423_B_
Content-Type: text/html; charset="iso - 8859 - 1"
Content-Transfer-Encoding: quoted-printable
<html><body>
<h1>Hello World</h1>
<p>This is a calendar event test</p>
</body></html>
--_CAL_B598a1969806776.58663423_B_
Content-Type: text/calendar; charset="utf - 8"; method=REQUEST
Content-Transfer-Encoding: base64
QkVHSU46VkNBTEVOREFSDQpNRVRIT0Q6UkVRVUVTVA0KUFJPRElEOi0vL1BIUC8vTWVl
dGluZ1JlcXVlc3QvL0VODQpWRVJTSU9OOjIuMA0KQkVHSU46VkVWRU5UDQpPUkdBTkla
RVI7Q049Sm9obiBEb2U6TUFJTFRPOmpvaG4uZG9lQGV4YW1wbGUuY29tDQpBVFRFTkRF
RTtST0xFPVJFUS1QQVJUSUNJUEFOVDtQQVJUU1RBVD1ORUVEUy1BQ1RJT047UlNWUD1U
UlVFO0NOPVlvdXIgTmFtZTpNQUlMVE86eW91cm5hbWVAZXhhbXBsZS5jb20NCkRFU0NS
SVBUSU9OOkhlbGxvIFdvcmxkIEV2ZW50DQpTVU1NQVJZOkhlbGxvIFdvcmxkIEV2ZW50
DQpEVFNUQVJUOjIwMTcwODE1VDE5MDAwMFoNCkRURU5EOjIwMTcwODE1VDIwMDAwMFoN
ClVJRDowMTIzNDU2Nzg5DQpDTEFTUzpQVUJMSUMNClBSSU9SSVRZOjUNCkRUU1RBTVA6
MjAxNzA4MDhUMjAwNDU3Wg0KVFJBTlNQOk9QQVFVRQ0KU1RBVFVTOkNPTkZJUk1FRA0K
U0VRVUVOQ0U6MA0KTE9DQVRJT046MTIzIEFueSBTdHJlZXQNCkJFR0lOOlZBTEFSTQ0K
QUNUSU9OOkRJU1BMQVkNCkRFU0NSSVBUSU9OOlJFTUlOREVSDQpUUklHR0VSO1JFTEFU
RUQ9U1RBUlQ6LVBUMTVNDQpFTkQ6VkFMQVJNDQpFTkQ6VkVWRU5UDQpFTkQ6VkNBTEVO
REFS
--_CAL_B598a1969806776.58663423_B_--
In case you are wondering, that Base64 encoding translates to:
BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:-//PHP//MeetingRequest//EN
VERSION:2.0
BEGIN:VEVENT
ORGANIZER;CN=John Doe:MAILTO:john.doe#example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Your Name:MAILTO:yourname#example.com
DESCRIPTION:Hello World Event
SUMMARY:Hello World Event
DTSTART:20170815T190000Z
DTEND:20170815T200000Z
UID:0123456789
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20170808T200457Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION:123 Any Street
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:REMINDER
TRIGGER;RELATED=START:-PT15M
END:VALARM
END:VEVENT
END:VCALENDAR
I think it's possible, according to the RFC, but I doubt that it's a good idea, as it appears to be a bit of a security hole.
Related
This question is a follow-up to: What are some methods to converting RTF text nodes in XML using XSLT 2 / Saxon HE 11.3?.
After implementing the answered solution, I ran the code against a large dataset. During the processing of all that data, an item in source RTF caused the application to error.
The error:
Error on line 11 column 92 of urn:from-string: SXXP0003 Error reported by XML parser: The element type "a" must be terminated by the matching end-tag "</a>".: The element type "a" must be terminated by the matching end-tag "</a>".
I took a look at the source xml, which contained several RTF HYPERLINK codes. Source:
<SPECORMETHOD>{\rtf1\ansi\deff0\uc1\ansicpg1252\deftab720{\fonttbl{\f0\fnil\fcharset1 Arial;}{\f1\fnil\fcharset1 Times New Roman;}{\f2\fnil\fcharset1 WingDings;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red128\green128\blue0;}\wpprheadfoot1\paperw12240\paperh15840\margl720\margr720\margt720\margb720\headery720\footery720\endnhere\sectdefaultcl{\*\generator WPTools_5.17;}{\stylesheet{\s1\li0\fi0\ri0\sb0\sa0\ql\vertalt\fs20 Normal;}{\s2\li0\fi0\ri0\sb0\sa0\ql\vertalt\fs20 Default Paragraph Font;}{\s3\li0\fi0\ri0\sb0\sa0\ql\vertalt\fs20\cf3\ul\sbasedon2 Hyperlink;}}{\pard\plain\plain\f1\fs36\par\pard\plain\plain\f1\fs36\par\plain\f1\fs28\tab 10\'94Flour Tortilla\par\plain\f1\fs28\tab Caesar \f1\b\i DIP\f1\i0 : {\field{\*\fldinst{HYPERLINK "..\\\\..\\\\SAUCES\\\\Dips\\\\Dip, Caesar.doc"}}{\*\fldtitle{..\\\\..\\\\SAUCES\\\\Dips\\\\Dip, Caesar.doc}}{\fldrslt{\f1\cf3\cs103\ul\cs3 Dip, Caesar.doc\plain\f1\fs28\b}}}\par\plain\f1\fs28\tab Ripped Romaine\par\plain\f1\fs28\tab Blackened Salmon julienne\par\plain\f1\fs28\tab Shaved Red Onion\par\plain\f1\fs28\tab Julienne Tomato\par\plain\f1\fs28\tab Grated Parmesan\par\plain\f1\fs28\tab Blackening spice: {\field{\*\fldinst{HYPERLINK "..\\\\..\\\\SPICE\\\\Blackening Spice.doc"}}{\*\fldtitle{..\\\\..\\\\SPICE\\\\Blackening Spice.doc}}{\fldrslt{\f1\cf3\cs103\ul\cs3 Blackening Spice.doc\plain\f1\fs28}}}\par\pard\plain\plain\f1\fs28\par\plain\f1\fs28 Method\par\plain\f1\fs28 Procedure Text \par\pard\plain\plain\f1\fs36\par}}</SPECORMETHOD>
For my purposes, the URL is not going to be a functional component, but for the sake of utility of this RTF conversion project, what might be needed to have the hyperlink codes work correctly, or to output them as text for reference? One way I can handle this is in the XSLT by intercepting the element, looking for the HYPERLINK code and replacing it with regular text.
The desired output for a hyperlink from this example would be (text only):
CAESAR DIP: ..\..\SAUCES\Dips\Dip, Caesar.doc
The only modification to the original code was in XSLT to do a check for an empty element when processing the <SPECORMETHOD>.
<xsl:choose>
<xsl:when test="string-length(SPECORMETHOD) > 0">
<rtf-as-xhtml>
<xsl:sequence select="tika:parse-rtf(SPECORMETHOD[string-length(.) > 0])"/>
</rtf-as-xhtml>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'[EMPTY]'"/>
</xsl:otherwise>
</xsl:choose>
I've built this project in Eclipse 2022-12 (4.26.0). It's a Maven project using Apache Tika 2.7.0, and Saxon HE 11.3, using Java SE 1.8. Special thanks to Martin H.
I have run your sample rtf through Tika and the supposed XHTML output is unfortunately not well-formed:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="X-TIKA:Parsed-By" content="org.apache.tika.parser.DefaultParser" />
<meta name="X-TIKA:Parsed-By" content="org.apache.tika.parser.microsoft.rtf.RTFParser" />
<meta name="Content-Type" content="application/rtf" />
<title></title>
</head>
<body><p />
<p />
<p> 10ā€¯Flour Tortilla</p>
<p> Caesar <b><i>DIP</i>: <a href="..\\..\\SAUCES\\Dips\\Dip, Caesar.doc">Dip, Caesar.doc</b><b /></b></p>
<p><b /> Ripped Romaine</p>
<p> Blackened Salmon julienne</p>
<p> Shaved Red Onion</p>
<p> Julienne Tomato</p>
<p> Grated Parmesan</p>
<p> Blackening spice: Blackening Spice.doc</p>
<p />
<p>Method</p>
<p>Procedure Text </p>
<p />
<p />
</body></html>
So the error is in the fragment <p> Caesar <b><i>DIP</i>: <a href="..\\..\\SAUCES\\Dips\\Dip, Caesar.doc">Dip, Caesar.doc</b><b /></b></p>.
I don't know for sure whether that is a problem with the input somehow not being proper rtf but it looks more like a bug in the Tia parser and ToXmlContentHandler.
I have raised the potential issue https://issues.apache.org/jira/browse/TIKA-3972
In the end, with the help of the Saxonica guys (thanks to Michael Kay and Norm Walsh) I have found a better (probably anyway) approach of using Saxon with the Tika parser; instead of using Tika's ToXMLContentHandler() and its toString() method result fed to Saxon's DocumentBuilder it is possible to pass a Saxon BuildingContentHandler to Tika's parser directly to get an XdmNode:
public static XdmNode parseRtfToHTML2(String rtf, Processor processor) throws IOException, SAXException, TikaException, URISyntaxException, SaxonApiException {
DocumentBuilder docBuilder = processor.newDocumentBuilder();
BuildingContentHandler handler = docBuilder.newBuildingContentHandler();
AutoDetectParser parser = new AutoDetectParser();
Metadata metadata = new Metadata();
try (InputStream stream = new ByteArrayInputStream(rtf.getBytes("utf8"))) {
parser.parse(stream, handler, metadata);
return handler.getDocumentNode();//docBuilder.build(new StreamSource(new StringReader(handler.toString())));
} catch (SaxonApiException e) {
throw new RuntimeException(e);
}
}
Using that approach, at least in a short test, no error is thrown for the hyperlink RTF example, see the updated project https://github.com/martin-honnen/SaxonTikaRtfTest1 for the code in more context.
I'm designing an API that receives a form post request from the front end. The front-end form contains both regular form
fields and a file upload field. Let's say the behaviour of a trivial front-end from show as below
<form>
<input type="file" name="image">
<input type="text" name="field_1">
<input type="text" name="field_2">
</form>
would result the following post request:
Content-Disposition: form-data; name="image"
Content-Type: application/octet-stream
===CONTENT OF THE IMAGE===
Content-Disposition: form-data; name="field_1"
value of field 1
Content-Disposition: form-data; name="field_2"
value of field 2
But another backend developer insisted that we should wrap all of the fields except the image into a json object so that the request appears like
Content-Disposition: form-data; name="image"
Content-Type: application/octet-stream
===CONTENT OF THE IMAGE===
Content-Disposition: form-data; name="body"
{
"field_1": "value of field 1",
"field_2": "value of field 2"
}
Our backend technology is Spring/Boot, and as a result, the latter design would greatly simplify our controller signature, like
public EmptyResponse acceptFormInput(
#RequestPart EmptyResponse body,
#RequestPart("file") MultipartFile file
)
It appears to me that the Controller should directly reflect what our API looks like. And the controller signature should reflect the API declaration. But that fellow developer argued that the nesting API design is also part of the W3C standard (in draft though), thus should be doable. (W3C plan)
I'm having trouble figuring out which is the common practice in designing such API. Any suggestion is appreciated.
My target is to modify MIME contents & add footer note in email, without changing it's behavior.
If email content content type is text/plain then I'm updating email content type to multipart/mixed as below:
Content-Type: multipart/mixed;
Boundary="--=_SAMPLE_MIME_BOUNDARY_"
email original data
----=_SAMPLE_MIME_BOUNDARY_
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
!-- Sample footer note --!
----=_SAMPLE_MIME_BOUNDARY_--
And if email content type is by default multipart/mixed then I'm updating email contents are as below:
Content-Type: multipart/mixed;
boundary="----=_SAMPLE_MIME_BOUNDARY_"
------=_SAMPLE_MIME_BOUNDARY_
Content-Type: text/plain;
Content-Transfer-Encoding: 8bit
email data
------=_SAMPLE_MIME_BOUNDARY_
Content-Type: application/octet-stream;
name="test_attachment"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test_attachment"
<<attachment data>>
------=_SAMPLE_MIME_BOUNDARY_
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit;
Content-Disposition: inline;
!-- Sample footer note --!
------=_20160127171644_62291--
But when I update email body then Outlook treat sample note as an attachment. And in case of Thunderbird when I click on forward email it will treat footer as an attachment.
So my questions are, Which is best way to add footer text in email?
Am I doing right? Suggest changes/pinpoints if anything wrong.
The MIME structure of your message is wrong. It needs to be
multipart/mixed
multipart/alternative
text/plain
text/html
application/octet-stream
My bootstrap sets encoding for all views:
protected function _initView () {
$view = new Zend_View();
// snip...
$view->setEncoding('utf-8');
// snip...
return $view;
}
However, this does not set encoding for my form validators. The StringLength uses its default encoding (I'm not sure which that is) and it counts diacritics as two characters.
I know I can set the 'encoding' => 'utf-8' option when creating the validator, but it's kind of pesky to update all validators across my entire (huge) application. Is there a way to set the encoding for all validators at the same time?
You normally shouldn't have a problem with that if you've sent the Content-Type very early + defined it in the HTML-Document.
In PHP you can send the Encoding at the Entry-Point (which is in Zend Framework the "index.php"-File):
header( 'Content-Type: text/html; charset=utf-8' );
In your HTML-Layout you should place the META-Tag within your HEAD-Tag:
<!-- do this only in: HTML5 -->
<meta charset="utf-8" />
<!-- do this only in: HTML4 -->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
And, of course, save every Source-File (HTML+PHP-Files) within the Project in UTF-8 (without BOM)
In ZF 1.1x the StringLength validator uses iconv_strlen:
int iconv_strlen(string $str [, string $charset = ini_set("iconv.internal_encoding")])
So one thing to try is to call ini_set (or iconv_set_encoding('internal_encoding', $encoding);).
May be a bit late, but this would be the full answer:
mb_internal_encoding('utf-8');
iconv_set_encoding('internal_encoding', 'utf-8');
I use MFMailComposeViewController to send a message in html format. If my html template contains the css styles:
<div class="margin:10 10 10 0"> Go To</div>
In this case it works good.
But if I send:
Go To
then I see the letter that comes with broken styles as there (3D is not my misprint)
<div style=3D"margin:10 10 10 10;">Go=C2=A0To</div>
Well as the letter goes broken when I insert in the template symbols from national alphabets.
Somebody can tell what the problem and check with yourself?
I revised my answer to add a second part of the solution:
I found two issues using MFMailComposeViewController to send HTML email with tags.
1) For any HTML body that ends up being encoded as quoted-printable, you must put line breaks such that no lines are > 76 chars.
2) The text within the tag should be wrapped within a to ensure that MFMailComposeViewController does not interpret the content as a link within a link.
For example, the following HTML:
<a href='http://link/to/my/site.com'>site.com</a>
was being turned into:
<a href='http://link/to/my/site.com'><a href='http://site.com'>site.com</a></a>
By changing my HTML body to:
<a href='http://link/to/my/site.com'><span>site.com</span></a>
the email was sent correctly.
A full example:
NSMutableString *body = [NSMutableString string];
// add HTML before the link here with line breaks (\n)
[body appendString:#"<h1>Hello User!</h1>\n"];
[body appendString:#"<span>Click Me!</span>\n"];
[body appendString:#"<div>Thanks much!</div>\n"];
Cheers!