My problem involves using JavaScript in a gmail sheet to search emails using getRawContent.
I've been using indexOf to get a particular data from the string, I'm able to find the starting point for the data I want to use.
For example var startxmailer = rawmail.indexOf("X-Mailer: ",0);, but I'm unable to identify or locate end of line/carriage return to give me an end point to use sub-string to get the data for example var allxmailer = rawmail.substring(endxmailer,test1);.
I've tried indexOf(/[\n,\r]/,0) and (/\r,\n,|\r|,\n,\$,\O,\x/).
I've put the section of text into a variable in the script and used the above to locate end of line/carriage return but not been to successful any assistance would be much appreciated as I would like to be able to different section of data from a email in Raw Content.
Try this:
var xmailer = (rawmail.match(/X-Mailer: (.*)/i) || [])[1];
This will get the content of the X-Mailer header into the xmailer variable, or undefined if no such header was found. This works because . explicitly matches everything that isn't a new line.
Related
this is my HTML
<div id="remove">Username</div>
and this is my JS code
function slice() {
var t = document.getElementById("remove");
t.textContent = t.textContent.slice(0, -3);
}
slice();
Username load from foreach
{foreach from=$last_user item=s}
{$s.date}
{$s.username}
{/foreach}
This code working and remove 3 letter but when right click on browser and look at page sources i can see "Username" !
I need remove three letter because of privacy and security .
something like
*** name or usern ***
Thank for help me !
The only secure way to make sure the client can't see a particular piece of information is to never send it to the client in the first place. Otherwise, there will always be a way for the client to examine the raw payloads of the network requests and figure out the information they aren't supposed to know.
You'll need to fix this on your backend - either hard-code in
<div id="remove">Usern</div>
or, for a more dynamic approach, use a template engine (or whatever's generating the HTML) and look up how to change strings with it. For example, in EJS, if user is an object with a username property, you could do
<div id="remove"><%= user.username.slice(0, -3) %></div>
Changing the content only with client-side JavaScript will not be sufficient, if you wish to keep some things truly private.
With Smarty, you can define a modifier that takes a string and returns all but the last three characters of it.
function smarty_modifier_truncate_three($string)
{
return substr($string, 0, -3);
}
and then in your template, replace
{$s.username}
with
{$s.username|truncate_three}
If you want only the first three characters, it's easier because you can use the built-in truncate.
{$s.username|truncate:3}
JS doesn't change the source, it can only change the DOM, so what you can do is to keep the element empty and add a value to it using js, but don't forget that js runs on the client's side so its better here to send the string from the server without the last 3 characters.
this is my first post here so I hope that I do this right. I have searched for a day or so now and I haven't been able to find any direction so far so I guess it's time to ask. I am not able to access an element in my XML file. I can load the XML file, and get it saved into a variable and then in the debugger I can navigate to the information that I want to load into my DOM but when I try to access it using ".innerHtml" it is returning an empty string. I have also tried making sure that I am pointing to the correct node(?) inside of the XML Element by adding the [0] location to the "batch".
Here is my function:
function getBatchNumber(xml){
let batchHTML = document.getElementById('batch');
let batch = xml.getElementsByTagName('DIALOG5');
var test = batch[0];
batchHTML.textContent = test.innerHtml;
//batchHTML.textContent = "3151414";
}
In the debugger when I hover over "test" I can see that innerHtml is in the tree and has the correct number I am after. Then when I hover over innerHtml it is showing me that it has a value of "".
Thank you for any help or insight into this.
I'd like to search using savedsearch.
Here my code snippet goes.
var searchresults = nlapiSearchRecord('item', search_id, null, null);
search_id is defined as parameter in text field.
This is suitelet script so if you couldn't find similar search_id in savedsearch then it throws exception.
To avoid this I'd like to check if there is any similar internal id in saved searches.
For instance if there are two saved searches which ids are customsearch1, customsearch2.
If search_id is 'cust' then it throws exception and script finished with error.
It shows this in script log
'That search or mass update does not exist.'
Looking forward to hearing from you soon.
Regard
You can do a saved search of saved searches. You could take the results and use regex to determine if there is a similiar one. Use trim plus regex.
You could prevent this by changing your search_id parameter to a List/Record of Saved Searches.
Any reason why it has to be a text field?
I'm looking for a way to figure out how to get the thread id for a particular email on Gmail, just before it is sent OR at the point where the send button is clicked.
Currently, I'm working with Javascript in order to scrape other items off the email and store them in a record which works pretty well for everything except the thread id.
The thread ID can be found after I send the email within the URL:
https://mail.google.com/mail/u/0/?shva=1#inbox/13ddda647539dcca
In this case, the thread id (if I'm right - is 13ddda647539dcca.
Any help would be appreciated.
If anyone is still interested - You can retrieve the thread id after the email is sent by observing the that appears at the top of the page. This span contains a link which has an attribute named 'param' which has the thread-id.
You could try:
var matched = window.location.hash.match(/[A-Za-z0-9]+$/);
if (matched) {
// Found alphanumeric string at end of hash
}
And you can get the value with matched[0].
window.location.hash should only grab the "#inbox/13ddda647539dcca" part. Then the regex is to match against any alphanumeric characters at the end of the string. So the fact that "inbox" is separated from the thread id by a "/" is important.
Of course, all of this depends on the reliability of Gmail keeping the URL following the same convention as it currently seems to be.
I'm writing a Dashboard widget in Dashcode, and on the back side, I've got a string for credits. I want to include the widget's version number in that string, but if possible, I want to programmatically grab it from the CFBundleVersion or CFBundleShortVersionString key in Info.plist to avoid having to change the number in multiple places if and when I update the widget.
Searches on Apple's developer documentation, Google and various forums have proven fruitless so far. What I'd like to know is whether there's a built-in way to do this that Apple included but forgot to mention (like var version = widget.version(); or something), or whether my script will have to pull in and parse the entire plist before plucking out the one value I actually want.
Thanks for any help you can provide!
I seem to have found the answer: use Dashcode's "data source" facility to read in Info.plist as an XML data source. From there, this blog post showed me how to traverse the plist's structure and get the correct string (in this case, the fifth <string> element in the file, corresponding to CFBundleShortVersionString.
The function I ended up with:
function getWidgetVersion() {
var dataSource = dashcode.getDataSource("infoPlist");
var version = dataSource.selection().valueForKey("dict").valueForKey("string")[4]; // This line and the previous could probably be combined for the sake of brevity
if (typeof(version) == 'string') {
document.getElementById("creditsLabel").innerHTML += version; //I'll change this to just pass the number on
}
}
Since the text of the creditsLabel div has already been started off with a localized string, I get a nice little label saying "Version 1.0".