My code:
message = "To: " + to + "\n";
message.append("From: " + from + "\n");
message.append("Subject: " + subject + "\n");
message.append("MIME-Version: 1.0\n");
message.append("Content-Type: multipart/mixed; boundary=frontier\n\n");
message.append( "--frontier\n" );
message.append( "Content-Type: text/plain; charset=UTF-8\n\n" );
message.append(body);
message.append("\n\n");
When I send email and using polish letters and English letters in body everything is ok - for example "ĄZKŁY". When I use only polish letters in body - for example "ĄĘĆŻŹÓŁŃŚąęćżźółńś" I get the chinese letters "ナ漂徲Q尮赕繜蟪駵".
EDIT:
I get the body from QPlainTextEdit, next I execute function sendEmail where the one of the argument is body. I add the text like:
sendEmail( plainTextEdit->toPlainText() )
And the sendEmail function is:
void sendEmail( const QString &body )
And next is my previous code, which is in the sendEmail function.
EDIT 2:
When I check body value using qDebug() there is a proper text like "ĄĘĆŁÓŹŻ".
Related
I have a button in a google-app-maker page, it's function is to sending Invoice by email. So once this button clicked, it will do two function.
1. Sending invoice by email.
2. Change status of EmailStatus to 'YES'.
/* var widgets = widget.parent.descendants; */
var to = "webmaster#myemail.com";
var subject = "Prepare Invoice : " + widget.datasource.item.Client_Name;
var msg = "Please Prepare Invoice for " + "\n\nClient Name : " +
widget.datasource.item.Client_Name + "\n\nService : " +
widget.datasource.item.Service + "\n\nCase : " +
widget.datasource.item.Subjects + "\n\nScope :" +
widget.datasource.item.Scope + "\n\nSubject : " +
widget.datasource.item.Subjects + "\n\nStart :" +
widget.datasource.item.Start + "\n\nInterim : " +
widget.datasource.item.Interim + "\n\nStatus :" +
widget.datasource.item.Statusx + "\n\nCA : " +
widget.datasource.item.Client_Ref + "\n\nBilling : " +
widget.datasource.item.Billing + "\n\nFee VS : " +
widget.datasource.item.Fee_VS + "\n\nFee VI" +
widget.datasource.item.Fee_VI + "\n\nNotes : " +
widget.datasource.item.Notes + "\n\nPrep Invoice : " +
widget.datasource.item.Prep_Invoice + "\n\nInvoiced : " +
widget.datasource.item.Prep_Invoice + "\n\nInvoice Number : " +
widget.datasource.item.Invoice_Number;
SendEmail(to, subject, msg);
widget.datasource.modes.create.item.EmailStatus = 'YES';
There's no problem with sending email, but for EmailStatus change to field have problem. It can not change value from NULL to 'YES'. Do you have any idea how to solved it ?
Thanks
Here is a scenario how to handle this assuming that your EmailStatus is just field in the same model/datasource as where you have all of your invoice information.
Delete this line of code:
widget.datasource.modes.create.item.EmailStatus = 'YES';
Change this line of code:
SendEmail(to, subject, message);
to:
SendEmail(to, subject, message, widget.datasource.item);
Change your client send email function to this:
function SendEmail(to, subject, message, item) {
google.script.run
.withSuccessHandler(function() {
item.EmailStatus = 'YES';
})
.withFailureHandler(function(error) {
//include a failure message popup or something here
})
.ServerSendEmailFunction(to, subject, message);
}
Hope this helps and solves your problem.
Is "EmailStatus" a field in the datasource of the widget, or is it a field in a different datasource? If it is actually a field in a different datasource/model, then you have to specify which record in that other datasource you want to connect to (in this case, the record called "Yes").
I'd recommend creating another server script function to set the status to "Yes" - here's the instructions for doing that: https://developers.google.com/appmaker/models/relations#server_script
Then call this new function in your success handler for the SendEmail function.
I am working on deleting the file from the Amazon from sfdc.
I have written the code for it when am sending the request to Amazon It through error:-
System.HttpResponse[Status=HTTP Version not supported, StatusCode=505]
kindly help me to solve this problem
How can I overcome this error to pass correct request?
Code:
Datetime expire = system.now().addDays(1);
String dateString = expire.formatGmt('yyyy-MM-dd')+'T'+ expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';
String stringToSign = 'DELETE\n' +
'\n' +
'\n' +
dateString + '\n' +
('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+fname).replaceAll(' ', '');
stringToSign = stringToSign.replaceAll(' ', '%20');
System.debug('FINDME::stringToSign - ' + stringToSign);
Blob mac = Crypto.generateMac('HMacSHA1',Blob.valueOf(stringToSign), Blob.valueOf(+awsKeySet[0].AWS_Secret_Key__c));
stringToSign = EncodingUtil.base64Encode(mac);
//String encoded = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
HttpRequest con = new HttpRequest();
con.setHeader('Authorization',+awsKeySet[0].AWS_AccessKey_Id__c+':' + stringToSign);
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
con.setHeader('Host',+awsKeySet[0].Name__c+'.s3.amazonaws.com');
//con.setHeader('Date', dateString);
con.setMethod('DELETE');
Http http = new Http();
HTTPResponse res = http.send(con);
System.debug('RES.GETBODY: ' + res.getBody() + ' RES.GETSTATUS: ' + res.getStatus() + ' CON.GETENDPT: ' + con.getEndPoint());
This kind of problem typically arises from an invalid URL in the HTTP request as can be seen in this post in Salesforce success community and this post in Salesforce StackExchange. This line here is where I would start:
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
There are references to an sobject field awsKeySet[0].Name__c and a variable fname that you resolve into your URL string.
Are you certain there are no spaces or unescaped characters in the underlying value of either of those?
ResponseHelper.Redirect("popup.aspx?file= "+ LogicLayer.ManualPath + _ddlPLCs.SelectedValue.ToString() + "\\" + _PLCRow[0][0].ToString() ,"_page", "menubar=0,width=100,height=100");
in the second page :
if (Request.QueryString["file"] != null)
{
LogicLayer.viewManual(Request.QueryString["file"].ToString());
}
i found that slash (\) characters is removed from the file path
are there any idea ???
The backslash (\) is not acceptable in a URL. You have to encode the characters to a %HEX value. In ASP.Net there is a method to encode a URL string, and one to decode the string.
In the View:
ResponseHelper.Redirect("popup.aspx?file= "+ System.Web.HttpUtility.UrlEncode(LogicLayer.ManualPath + _ddlPLCs.SelectedValue.ToString() + "\\" + _PLCRow[0][0].ToString()) ,"_page", "menubar=0,width=100,height=100");
In the Code Behind:
if (Request.QueryString["file"] != null)
{
LogicLayer.viewManual(HttpServerUtility.UrlDecode(Request.QueryString["file"].ToString()));
}
Here's a similar question.
I'm sending back a bunch of image tags via JSON in my .ashx response.
I am not sure how to format this so that the string comes back with real tags. I tried to HtmlEncode and that sort of fixed it but then I ended up with this stupid \u003c crap:
["\u003cimg src=\"http://www.sss.com/image/65.jpg\" alt=\"\"\u003e\u003c/li\u003e","\u003cimg src=\"http://www.xxx.com/image/61.jpg\" alt=\"\"\u003e\u003c/li\u003e"]
What the heck is \u003c ?
here's my code that created the JSON for response to my .ashx:
private void GetProductsJSON(HttpContext context)
{
context.Response.ContentType = "text/plain";
int i = 1;
...do some more stuff
foreach(Product p in products)
{
string imageTag = string.Format(#"<img src=""{0}"" alt=""""></li>", WebUtil.ImageUrl(p.Image, false));
images.Add(imageTag);
i++;
}
string jsonString = images.ToJSON();
context.Response.Write(HttpUtility.HtmlEncode(jsonString));
}
the toJSON is simply using the helper method outlined here:
http://weblogs.asp.net/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx
\u003c is an escaped less-than character in unicode (Unicode character 0x003C).
The AJAX response is fine. When that string is written to the DOM, it will show up as a normal "<" character.
You are returning JSON array. Once parsed using eval("("+returnValue+")") it is in readily usable condition.
EDIT: This code is from jquery.json.js file:
var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
var meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
};
$.quoteString = function(string)
// Places quotes around a string, inteligently.
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
{
if (escapeable.test(string))
{
return '"' + string.replace(escapeable, function (a)
{
var c = meta[a];
if (typeof c === 'string') {
return c;
}
c = a.charCodeAt();
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
}) + '"';
}
return '"' + string + '"';
};
Hope this gives you some direction to go ahead.
all you need to do is to use javascript eval function to get a pure HTML (XML) markup on the front end.
i.e. in a ajax call to a webservice, this can be the success handler of tha call,
the service returns a complex html element:
...
success: function(msg) {$(divToBeWorkedOn).html(**eval(**msg**)**);alert(eval(msg));},
...
How do I detect what browser (IE, Firefox, Opera) the user is accessing my site with? Examples in Javascript, PHP, ASP, Python, JSP, and any others you can think of would be helpful. Is there a language agnostic way to get this information?
If it's for handling the request, look at the User-Agent header on the incoming request.
UPDATE: If it's for reporting, configure your web server to log the User-Agent in the access logs, then run a log analysis tool, e.g., AWStats.
UPDATE 2: FYI, it's usually (not always, usually) a bad idea to change the way you're handling a request based on the User-Agent.
Comprehensive list of User Agent Strings from various Browsers
The list is really large :)
You would take a look at the User-Agent that they are sending. Note that you can send whatever agent you want, so that's not 100% foolproof, but most people don't change it unless there's a specific reason to.
A quick and dirty java servlet example
private String getBrowserName(HttpServletRequest request) {
// get the user Agent from request header
String userAgent = request.getHeader(Constants.BROWSER_USER_AGENT);
String BrowesrName = "";
//check for Internet Explorer
if (userAgent.indexOf("MSIE") > -1) {
BrowesrName = Constants.BROWSER_NAME_IE;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_FIREFOX) > -1) {
BrowesrName = Constants.BROWSER_NAME_MOZILLA_FIREFOX;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_OPERA) > -1) {
BrowesrName = Constants.BROWSER_NAME_OPERA;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_SAFARI) > -1) {
BrowesrName = Constants.BROWSER_NAME_SAFARI;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_NETSCAPE) > -1) {
BrowesrName = Constants.BROWSER_NAME_NETSCAPE;
} else {
BrowesrName = "Undefined Browser";
}
//return the browser name
return BrowesrName;
}
You can use the HttpBrowserCapabilities Class in ASP.NET. Here is a sample from this link
private void Button1_Click(object sender, System.EventArgs e)
{
HttpBrowserCapabilities bc;
string s;
bc = Request.Browser;
s= "Browser Capabilities" + "\n";
s += "Type = " + bc.Type + "\n";
s += "Name = " + bc.Browser + "\n";
s += "Version = " + bc.Version + "\n";
s += "Major Version = " + bc.MajorVersion + "\n";
s += "Minor Version = " + bc.MinorVersion + "\n";
s += "Platform = " + bc.Platform + "\n";
s += "Is Beta = " + bc.Beta + "\n";
s += "Is Crawler = " + bc.Crawler + "\n";
s += "Is AOL = " + bc.AOL + "\n";
s += "Is Win16 = " + bc.Win16 + "\n";
s += "Is Win32 = " + bc.Win32 + "\n";
s += "Supports Frames = " + bc.Frames + "\n";
s += "Supports Tables = " + bc.Tables + "\n";
s += "Supports Cookies = " + bc.Cookies + "\n";
s += "Supports VB Script = " + bc.VBScript + "\n";
s += "Supports JavaScript = " + bc.JavaScript + "\n";
s += "Supports Java Applets = " + bc.JavaApplets + "\n";
s += "Supports ActiveX Controls = " + bc.ActiveXControls + "\n";
TextBox1.Text = s;
}
PHP's predefined superglobal array $_SERVER contains a key "HTTP_USER_AGENT", which contains the value of the User-Agent header as sent in the HTTP request. Remember that this is user-provided data and is not to be trusted. Few users alter their user-agent string, but it does happen from time to time.
On the client side, you can do this in Javascript using the navigation.userAgent object. Here's a crude example:
if (navigator.userAgent.indexOf("MSIE") > -1)
{
alert("Internet Explorer!");
}
else if (navigator.userAgent.indexOf("Firefox") > -1)
{
alert("Firefox!");
}
A more detailed and comprehensive example can be found here: http://www.quirksmode.org/js/detect.html
Note that if you're doing the browser detection for the sake of Javascript compatibility, it's usually better to simply use object detection or a try/catch block, lest some version you didn't think of slip through the cracks of your script.
For example, instead of doing this...
if(navigator.userAgent.indexOf("MSIE 6") > -1)
{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
objXMLHttp = new XMLHttpRequest();
}
...this is better:
if(window.XMLHttpRequest) // Works in Firefox, Opera, and Safari, maybe latest IE?
{
objXMLHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) // If the above fails, try the MSIE 6 method
{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
It may be dependent of your setting. With apache on linux, its written in the access log /var/log/apache2/access_log
You can do this by:
- looking at the web server log, OR
- looking at the User-Agent field in the HTML request (which is a plain text stream) before processing it.
First of all, I'd like to note, that it is best to avoid patching against specific web-browsers, unless as a last result -try to achieve cross-browser compatibility instead using standard-compliant HTML/CSS/JS (yes, javascript does have a common denominator subset, which works across all major browsers).
With that said, the user-agent tag from the HTTP request header contains the client's (claimed) browser. Although this has become a real mess due to people working against specific browser, and not the specification, so determining the real browser can be a little tricky.
Match against this:
contains browser
Firefox -> Firefox
MSIE -> Internet Explorer
Opera -> Opera (one of the few browsers, which don't pretend to be Mozilla :) )
Most of the agents containing the words "bot", or "crawler" are usually bots (so you can omit it from logs / etc)
check out browsecap.ini. The linked site has files for multiple scripting languages. The browsecap not only identifies the user-agent but also has info about the browser's CSS support, JS support, OS, if its a mobile browser etc.
cruise over to this page to see an example of what info the browsecap.ini can tell you about your current browser.