how to transfer body.getAsync plain text with \n - outlook

I'm getting outlook email content with
Office.context.mailbox.item.body.getAsync("text", async function callback(result) {})
and the result it returned is in plain text format with no line breaks info, I want to know if there is any way to get it with \n ?

You can get the HTML string which represents the message body instead.

Related

How to make Get Request with Request param in Postman

I have created an endpoint that accepts a string in its request param
#GetMapping(value = "/validate")
private void validateExpression(#RequestParam(value = "expression") String expression) {
System.out.println(expression);
// code to validate the input string
}
While sending the request from postman as
https://localhost:8443/validate?expression=Y07607=Curr_month:Y07606/Curr_month:Y07608
// lets say this is a valid input
console displays as
Y07607=Curr_month:Y07606/Curr_month:Y07608 Valid
But when i send
https://localhost:8443/validate?expression=Y07607=Curr_month:Y07606+Curr_month:Y07608
//which is also an valid input
console displays as
Y07607=Curr_month:Y07606 Curr_month:Y07608 Invalid
I am not understanding why "+" is not accepted as parameter.
"+" just vanishes till it reaches the api! Why?
I suggest to add this regular expression to your code to handle '+' char :
#GetMapping(value = "/validate")
private void validateExpression(#RequestParam(value = "expression:.+") String expression) {
System.out.println(expression);
// code to validate the input string
}
I didn't find any solution but the reason is because + is a special character in a URL escape for spaces. Thats why it is replacing + with a " " i.e. a space.
So apparently I have to encode it from my front-end
Its wise to encode special characters in a URL. Characters like \ or :, etc.
For + the format or value is %2. You can read more about URL encoding here. This is actually the preferred method because these special characters can sometimes cause unintended events to occur, like / or = which can mean something else in the URL.
And you need not worry about manually decoding it in the backend or server because it is automatically decoded, in most cases and frameworks. In your case, I assume you are using Spring Boot, so you don't need to worry about decoding.

Change codemirror render function in show-hint.js

I would like to modify rendering hints in code mirror using
render: fn(Element, self, data) in show-hint.js with some id and replace those IDs in hint text inserted while reading value from codemirror using getValue()
Sample hint:
displayText : test
text: %%test%%
And the text should be mapped with some id in the background, it should be retrieved while getting value from the codemirror when the text in the codemirror contains special character '%%'
Could anyone please, help me to achieve this.

Deleting the "\r" or carriage return from a string in Ruby

I am using CloudMailin to receive emails and then send the plain text to my Ruby on Rails app. To access the body of the email in plain text I use params[:plain].
If I were to just print the relevant part of the plain text it would look like this:
Style 130690 113
Price $335.00
Stock # 2882524
I have used regex to name capture certain pieces of data:
style, price, stock = params[:plain].scan(/^(?:Style |Price \$|Stock \# )(.+)/).flatten
This works however each variable has a "\r" or carriage return at the end. So, if stock is 80201943, it would appear in my database as "80201943\r".
I then try to update my database with this code:
shoe = Shoe.where(:size => "7").first
shoe.update_column(:stockId, stock)
Then when I check my database the :stockId has a "\r" at the end of it.
I have tried doing
stock.chomp("\r")
stock.chomp
stock.strip
stock.gsub("\r", ""),
None of these remove the "\r" from the string. How can I remove it?
I was not altering the variable, I was just returning a new one. To alter the variable I needed to use:
stock.chomp!

Best way to find nested opening and closing tags

I am making a basic discussion board using ROR. When a user posts a response to a message, the input textarea is prepopulated with the message in quotes using a tag: [QUOTE]. As such the format is:
[QUOTE]quoted message goes here[/QUOTE]
Currently, I have a simple solution that replaces [QUOTE] and [/QUOTE] with HTML using message.sub('[QUOTE]', 'html goes here') as long as [QUOTE] or [/QUOTE] still exist. When I go to respond to a quoted message, I convert the HTML back into the [QUOTE] tag to ensure that the prepopulated input textarea doesn't have HTML in it. As such, a quote of a quote, will look like:
[QUOTE][QUOTE]quoted message here[/QUOTE][/QUOTE]
Here is the problem. If I run my current method again, I will get duplicated HTML fields like:
<div class='test'><div class='test'>quoted message goes here</div></div>
Instead, I want to be able to have a solution that looks like:
<div class='test1'><div class='test2'>quoted message goes here</div></div>
And so on...
Any suggestions on the best way to loop this?
If you want to do depth tracking you'll have to use the block method for gsub:
text = "[QUOTE][QUOTE]quoted message here[/QUOTE][/QUOTE]"
quote_level = 0
new_text = text.gsub(/\[\/?QUOTE\]/) do |m|
case (m)
when '[QUOTE]'
quote_level += 1
"<div class='test#{quote_level}'>"
when '[/QUOTE]'
quote_level -= 1
"</div>"
end
end
puts new_text.inspect
# => "<div class='test1'><div class='test2'>quoted message here</div></div>"
You could make this more robust when handling invalid nesting pairs, but for well-formatted tags this should work.
Here's an idea:
Take this regex
(\[QUOTE\])(.*?)(\[\/QUOTE\])
And apply it to your string. It'll match opening tag, closing tag and content. Then take the content and apply regex again. If there are any matches, that'll be your second level of nesting. Repeat while have matches.
Demo here: http://rubular.com/r/MkGsnUj3vL

How to pass & (ampersand symbol) in ajax get or post method?

I have a text box to enter description
If i submits that need to be send through ajax and store in db.
Problem:-
Example text in textbox:- "Hi all & solve my problem"
in the next page i am getting till "Hi all"
Remaining text is missing, If I pass through get or post method using ajax.
Give me the solution. How to get all the content I placed in text box along with "&"
You need to urlencode string with escape or encodeURIComponent functions.
Yes, I have faced same type issue and find out solution that we need to pass data as a key value pair,
I had passed data in Ajax like:
data : email=" + email + "&name='" + name
But right way for passing data in Ajax is :
data: {
email : email,
name : name
}

Resources