Google apps script, getBody() from Gmail, regex \n - regex

Good evening. Have such problem with regex new-line character ("\n") in Google app script. I'm using .getbody() method for mail parse and get some of this
<td valign="middle" width="43" align="left">
<img src="http://img/mail-new-oct/icon2.png" style="display: block; vertical-align: middle;" alt="Logo">
</td>
<td align="center" valign="top" style="font-family: 'Open Sans', Helvetica, 'Helvetica Neue', Arial, sans-serif; font-size: 13px; line-height: 30px; color: #000000; font-weight: 400; text-align: left;">0972398182
</td>
For this part, i need phone number 0972398182.
I try get it with this expression:
icon2.*\n.*\n.*>\s*([\s\S]+?)\s*(?=<\/td>)
icon2 - is one unique identification for this html body, so i need to use it. Go through without ("\n") impossible in this way, and finally it doesn't work. I read, that GAS doesn't work with ("\n") , but maybe have other way how to solve this? Will be grateful for any help, thanks!

You seem to have a combination of newlines and carriage returns in your input string. That means you may use [\r\n]+ character class with + quantifier:
icon2.*[\r\n]+.*[\r\n]+.*left.*>\s*(.+?)\s*(?=<\/td>)

Please try the given workaround in Issue #13 logged in google-apps-script-issues tracker. Use:
\\n.
In addition to that, you may want to also check solutions given in the following posts:
\n not working in google apps script Browser.msgBox
How to add line breaks in a cell before specific keywords in Google Sheets

Related

AWS SES New Virtual Deliverability Manager - Trackinglinks are not replaced in roundrect elements

Today I tried the new "Virtual Deliverability Manager" feature of AWS SES. Here I immediately noticed a problem with our emails.
For Outlook, there is an extra markup element "v:roundrect" in our email template.
The href in this element is not replaced by the tracking link from AWS.
All other links from our template are successfully replaced.
Snippet of our Email-Template:
<div align="center">
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://MYWEBSITE.com/produkt/#Model.ProductNumber" style="height:40px;v-text-anchor:middle;width:200px;" arcsize="10%" strokecolor="#800500" fillcolor="#da251d">
<w:anchorlock/>
<center style="color:#ffffff;font-family:sans-serif;font-size:13px;font-weight:bold;">Jetzt Bestellen!</center>
</v:roundrect>
<![endif]-->
Jetzt Bestellen!
</div>
Link in other EmailClients (Correct - replaced):
Link in Outlook (Incorrect - Not replaced):
Has anyone had similar experience in this regard?
It looks like AWS SES only replaces the classic a-tag hrefs.
Unfortunately I didn't find anything in their documentation about this.
My temporary workaround:
(No fix!)
I changed the Html of my Template. As a result, the button in Outlook no longer has the desired rounded edges. But now the tracking works.
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="padding: 12px 18px 12px 18px; border-radius:5px; background-color: #da251d;" align="center">
<a rel="noopener" target="_blank" href="https://MYWEBSITE.com/produkt/#Model.ProductNumber" target="_blank" style="font-size: 18px; font-family: Helvetica, Arial, sans-serif; font-weight: bold; color: #ffffff; text-decoration: none; display: inline-block;">Jetzt Bestellen!</a>
</td>
</tr>
</table>
Currently AWS is scanning only the links that are presented in the email and converting them. There is only possibility to remove the specific links from tracking using additional ses:no-track
Here is an example:
<a ses:no-track href="aws.amazon.com">Amazon Web Services</a>
On the other hand they do not allow(YET, maybe in the future) to provide a field to specifically convert some links in the other elements (as in your case

HTML tag <a> does not appear in Gmail and Outlook (maybe others)

I must repair a bug on the emails sent by my company when a new customer's account is created for the website, it must show a HTML <a> tag with the link to go on the new account, but in Gmail and Outlook, this <a> tag does not appear.
The code just here:
<tr>
<td style="font-size: 0px; padding: 10px 25px; padding-top: 30px; padding-bottom: 30px;
word-break: break-word;" align="center">
<table style="border-collapse: separate; line-height: 100%;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border: none; border-radius: 37px; cursor: auto; mso-padding-alt: 10px 25px;
background: #5F9AB0;" align="center" valign="middle" bgcolor="#5F9AB0"> Demander mon mot de passe
</td>
</tr>
</tbody>
</table>
</td>
</tr>
Screenshot of expected result (actual when I read my mail with the Mail mac app)
Screenshot of the display of the mail in Chrome and Firefox using Gmail and Outlook webapp
#Syfer suggested email queries are involved. If they are, check out https://www.caniemail.com/search/?s=media.
That says support for media queries is absent or spotty for all Gmails, all the Outlooks (except for the one that uses Apple Mail), all Yahoo's, all AOL's, and others.
Ain't it grand writing email HTML? 😁

GATE developer_Requesting for Suggestion

I wanted to post the highlighted annotation of a document [highlighted using GATE developer tool] to new file [either word or Excel]. Can someone help me with any suggestions or this?
Thanks in Advance.
Regards,
Gayatri
Sorry, I can't comment yet...
Similar question here Read annotated data from GATE datastore
The provided answer (By Ian Roberts) has means to store selected annotations in files.
Suggestion: Use GATE embedded (with Java).
Reading annotated documents in html is fairly straight forward. You can follow the instructions for printing which can be executed using a text editor. Remember to select the annotations you wish to display and save the artifact using the ‘Save Preserving Format’. The resulting xml will have the annotation tags you select embedded in the saved document.
You can also visualize in html.
<!DOCTYPE html>
<div id="topContent">
<h1>Report Example</h1>
<p>
This example provide a visualization of a annotated document produced by GATE using ANNIE with defaults. To use with Javascript, the document can be formatted as an xml document using xmlHttpRequest.
</p>
</div>
<div id="pageView">
<div id="legendView">
<h3>Document Legend</h3>
<div>
<table id="annotationTable">
<tr>
<th>Facet</th>
<th>Color</th>
</tr>
<tr>
<td>Date</td>
<td id="dateFill"></td>
</tr>
<tr>
<td>Location</td>
<td id="locationFill"></td>
</tr>
<tr>
<td>Organization</td>
<td id="organizationFill"></td>
</tr>
<tr>
<td>Person</td>
<td id="personFill"></td>
</tr>
</table>
</div>
</div>
<p>..Add GATE XML contents here..</p>
</div>
Once the html is set up, add the css:
body {}
table, th, td {
border: 1px solid black;
text-align: center;
font-family: arial;
}
#annotationTable {
border-collapse: collapse;
width: 10%;
}
#topContent {
font: 18px arial;
}
#pageView {
border: 1px solid black;
font: 14px arial;
}
#legendView {
margin: 10px 10px 10px 10px;
}
#dateFill {background-color: rgb(51, 255, 119)}
#locationFill {background-color: rgb(204, 153, 255)}
#organizationFill {background-color: rgb(102, 255, 255)}
#personFill {background-color: rgb(255, 204, 153)}
Date {background-color: rgb(51, 255, 119)}
Location {background-color: rgb(204, 153, 255)}
Organization {background-color: rgb(102, 255, 255)}
Person {background-color: rgb(255, 204, 153)}
This provides a basic view of the GATE annotations. Of course it can be more complicated depending on what you are trying to express. See the Fiddle
To view in MS Word:
Open the saved annotated xml file in MS Word.
Add the css file to the same directory where the annotated document is stored.
Open the Developer Tab in Word.
Select the Document Template icon.
Select the Linked CSS tab, navigate to the location of the annotated document and css file.
Add the css file to the Linked Style Sheets.
Save the document as a Web Page.
Navigate to where you saved the html page and open in your favorite browser.
Ensure that you have selected Print Background Colors and Images from the Page Setup.
Print for a highlighted document.
Kind of a pain in the butt but it works if you want a printed copy. The document will not present css in Word. I hope this helps.

Regex extract string only contains img tag between span tags

I have requirement to fetch only images which are under anchor and span tags.
Can some one provide solution to fetch images.
Thanks in advance.
details:
sample code link: http://regexr.com/v1?38u5g
RegEx1: <a (.*?)><span (.*?)>(.*?)<\/span><\/a>
RegEx2: <a (.*?)><span (.*?)><img(.*?) \/><\/span><\/a>
sample Code:
<span style="font-size: 1.2em;">We voted for our next selection as well. The choice was between Joan Didion's </span><span style="font-size: 1.2em;">The Year of Magical Thinking</span><span style="font-size: 1.2em;">, Sarah Dunant's </span><span style="font-size: 1.2em;">In the Company of the Courtesan</span><span style="font-size: 1.2em;">, </span><span style="font-size: 1.2em;">Jodi Picoult's</span> <span style="font-size: 1.2em;">My Sister's Keeper</span><span style="font-size: 1.2em;">, Jhumpa Lahiri's </span><span style="font-size: 1.2em;">The Namesake</span><span style="font-size: 1.2em;"> and </span><span style="font-size: 1.2em;">When the Emperor Was Divine</span><span style="font-size: 1.2em;"> by Julie Otsuka. </span><span style="font-size: 1.2em;"><img style="float: left; margin: 0px 5px 5px 0px;" title="Joan_didion" src="joan_didion.jpg" alt="Joan_didion" width="100" height="88" border="0" /></span><span style="font-size: 1.2em;"> Joan Didion was the clear winner though many of us are approaching it with some trepidation as we know it will be a very emotional read. Perhaps we'll make a field trip to see the </span><span style="font-size: 1.2em;">play</span><span style="font-size: 1.2em;">. Kudos to R. who hosted with excellent fare (thank goodness as it served as my dinner) and who served an amazing </span><span style="font-size: 1.2em;">lemon olive oil cake</span><span style="font-size: 1.2em;">. It sounds weird, but is delicious.</span>
Regards,
Faruq Shaik.
This captures the target <img>...</img> tag as group 1 of the match:
<a [^>]*>(<span [^>]*>)?(<img[^>]* \/>)(<\/span>)?<\/a>
See demo.
The trick here is to use [^>]* rather than .*? to consume only the attributes of the tag and thus correctly match the nearest parent.

CKEditor "protects" me from inline stylesheets

I'm trying to integrate CKEditor into Wordpress for a client. I'm not too familiar with it, it's the first time I use it.
The client wants to use CKEditor on a textarea that gets stored into a custom field and is displayed in the sidebar of a page.
I added support for this form of editing by adding meta boxes to the page edit window. I have FCKEditor plugin installed, so I just call CKEditor.replace on the relevant metabox.
The problem is that when the meta box contains THIS: (I trimmed the CSS for convenience. There's actually quite a bit).
<style type="text/css">
<!--
.side-banner .style1 {
font-family: Arial;
font-size: 14px;
}
.side-banner .style2 {
font-family: Helvetica;
font-size: 12px;
-->
</style>
<table width="246" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="246" height="15" colspan="2" scope="col"> </th>
CKEditor turns it into this:
<p><style type="text/css">
<!--{cke_protected}%3C!%2D%2D%0A.side-banner%20.style1%20%7B%0A%09font-family%3A%20Arial%2C.side-banner%20.style2%20%7B%0A%09font-family%3A%20Arial%2C%20Helvetica%2C%20sans-serif%3B-->
</style></p>
<table border="0" cellpadding="0" cellspacing="0" width="246">
<tbody>
<tr>
My client insists on editing the sidebox at the CSS/HTML level rather than just content, and I'd like to provide what is requested rather than spend time educating them (this, perhaps, is a topic for another S.O. question?).
I realise this has to do with CKEDITOR.config.protectedSource but I found very little documentation to help me, and I wouldn't know what kind of RegEx to provide to avoid this.
How do I keep CKEditor from gobbling up the HTML/CSS code in this <textarea> tag?
Remove the HTML comments (<!-- and -->) from the <style>
Edit: It's tracked in this ticket http://dev.fckeditor.net/ticket/4880