how to get the file sent in xml response in perl? - perl

Using the LWP user agent I am sending the request and getting the response.
I will get the response in html format and a file attached in it.
eg:
`<html>
<head>
<title>Download Files</title>
<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/main.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/Menu.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'/statsdoc/freeze.css\' type=\'text/css\'>
</head>
<body>
<table border=1>
<tr class=\'rightTableData\'>
<th>No.</th>
<th>File Name</th>
<th>File Size</th>
</tr><tr class=\'rightTableData\'>
<td>1</td><td>
<a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE /20160329/LSUZisbZahtHNeImZJm_1-1.csv.zip\'>1-1.csv.zip</a>
</td><td>487 bytes</td> </tr>
</table>
</br></br>
<center><a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE/20160329/LSUZisbZahtHNeImZJm-csv.zip\'>Download all</a></center>
</body></html>`
From this response I need to get the file. Can anyone help me to get the file from response.

Use a parser to extract the information. I used XML::LibXML, but I had to remove the closing br tags that made the parser fail.
#!/usr/bin/perl
use warnings;
use strict;
my $html = '<html>
<head>
<title>Download Files</title>
<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/main.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/Menu.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'/statsdoc/freeze.css\' type=\'text/css\'>
</head>
<body>
<table border=1>
<tr class=\'rightTableData\'>
<th>No.</th>
<th>File Name</th>
<th>File Size</th>
</tr><tr class=\'rightTableData\'>
<td>1</td><td>
<a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE /20160329/LSUZisbZahtHNeImZJm_1-1.csv.zip\'>1-1.csv.zip</a>
</td><td>487 bytes</td> </tr>
</table>
<!-- </br></br> I had to comment this out! -->
<center><a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE/20160329/LSUZisbZahtHNeImZJm-csv.zip\'>Download all</a></center>
</body></html>';
use XML::LibXML;
my $dom = 'XML::LibXML'->load_html( string => $html );
print $dom->findvalue('/html/body/table/tr[2]/td[2]/a/#href');
You could also use the recover flag to parse invalid HTML:
my $dom = 'XML::LibXML'->load_html( string => $html, recover => 1 );

Related

codeigniter sending email with logo not working

I'm using CI version 3 and I'm using the built in email functionality to send an HTML email template.
My code is as following:
public function send_email($sendTo, $fromName, $fromEmail, $data, $subject) {
$this->email->set_mailtype('html');
$this->email->from($fromEmail, $fromName);
$this->email->to($sendTo);
$this->email->subject($subject);
$this->email->attach(FCPATH . "images/logo.png", "inline");
$content = array(
'HTMLcontent' => $data
);
$body = $this->load->view('email_template.php', $content, TRUE);
$this->email->message($body);
if ($this->email->send()) {
return TRUE;
} else {
return FALSE;
}
}
The FCPATH is ok it shows : /home/myuser/public_html/ and I have images folder inside public_html
email_template.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table>
<tr>
<td>
<a href="" target="_blank">
<img src="cid:logo.png" width="144" height="76" border="0" alt="logo"/>
</a>
</td>
</tr>
</table>
</body>
</html>
When the email comes it shows with a missing logo as the image below

ASP, vbscript, CDO Email through AWS is truncated?

I am moving this classic ASP app to AWS and using AWS SES SMTP to send site emails (automated, post registration email).
So, the code below works but when the email arrives it is truncated (incomplete)?
Mail Function:
Function Sendmail(Sender, Subject, Recipient, Body)
dim myMail, strServer
strServer = Request.ServerVariables("server_name")
if strServer <> "localhost" then
Set myMail=Server.CreateObject("CDO.Message")
myMail.Subject=Subject
myMail.From=Sender
myMail.To=Recipient
myMail.HTMLBody=Body
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="email-smtp.us-east-1.amazonaws.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
'requires authentication
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'username
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername")="a username"
'password
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword")="a password"
'startTLS
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=true
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
end if
End function
Mail Body
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><html lang='en'><head> <meta http-equiv='Content-Type' content='text/html; charset=windows-1258'> <meta name='viewport' content='width=device-width, initial-scale=1'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <meta name='format-detection' content='telephone=no'> <title>Title</title> <link rel='stylesheet' type='text/css' href='http://www.website.com/styles.css'> <link rel='stylesheet' type='text/css' href='http://www.website.com/responsive.css'></head><body style='margin:0; padding:0;' bgcolor='#F0F0F0' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><table border='0' width='100%' height='100%' cellpadding='0' cellspacing='0' bgcolor='#F0F0F0'><tr><td align='center' valign='top' bgcolor='#F0F0F0' style='background-color: #F0F0F0;'> <br/> <table border='0' width='600' cellpadding='0' cellspacing='0' class='container'><tr><td class='header' align='left'><img src='http://www.website.com/images/email/logo_small_en.png'/> </td></tr><tr> <td class='container-padding content' align='left' bgcolor='#FFFFFF'> <br/><div class='title'>Welcome to the site! </div><br/><div class='body-text'> <p>Welcome to the website<div class='hr'></div><br/><div class='subtitle'>Have fun!</div><br/> </td></tr><tr> <td class='container-padding footer-text' align='left'><br/>© 2016 <br/> <br/>You are receiving this email because you registered for the website. Please click here to <a href=''>unsubscribe</a>. <br/> </td></tr></table></td></tr></table></body></html>
Truncated always at the same spot?
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><html lang='en'><head> <meta http-equiv='Content-Type' content='text/html; charset=windows-1258'> <meta name='viewport' content='width=device-width, initial-scale=1'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <meta name='format-detection' content='telephone=no'> <title>Title</title> <link rel='stylesheet' type='text/css' href='http://www.website.com/styles.css'> <link rel='stylesheet' type='text/css' href='http://www.website.com/responsive.css'></head><body style='margin:0; padding:0;' bgcolor='#F0F0F0' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><table border='0' width='100%' height='100%' cellpadding='0' cellspacing='0' bgcolor='#F0F0F0'> <tr> <td align='center' valign='top' bgcolor='#F0F0F0' style='background-color: #F0F0F0;'> <br/> <table border='0' width='600' cellpadding='0' cellspacing='0' class='container'> <tr> <td class='he
I can't seem to track this down? Is the error in my function or the mail body? Is it an AWS limitation?
Thanks for your thoughts,
SMTP servers can throw a "Line too long" error when a line of the email exceeds some server-defined length. Since your message is always truncated at the same spot try inserting line breaks into your message body. I know AWS SES SMTP can return this error but I am unsure as to what the limit is. Here is a related conversation with a similar error and CDO for reference.
CDO uses 7bit for content transfer encoding by default, which does not truncate the long lines.
You don't need a user defined function but specify an appropriate content transfer encoding for the message body.
8bit, quoted-printable and base64 are standard transfer encodings will take care of the long lines.
'...
myMail.Configuration.Fields.Update
myMail.HTMLBodyPart.ContentTransferEncoding = "8bit"
myMail.Send
'...

Replacing XML nodes using perl and Mojo::DOM

I would like to exchange node in an XML file using Mojo::DOM.
I'm pretty sure it is possible but I didn't find a way yet.
Given the following XML:
my $xml = q~
<html>
<div>
<p>1</p>
<p>2</p>
<img />
</div>
</html>
~;
I would like to remove the div and instead insert a body tag, so that the result looks like this:
my $xml = q~
<html>
<body>
<p>1</p>
<p>2</p>
<img />
</body>
</html>
~;
I thought about replace, but I didn't find an example where the replacement is the $dom of the replaced tag.
It's very simple to just find the <div> element and use the tag method to change its tag
This program demonstrates. The CSS selector html > div finds the (first) <div> element that is a child of an <html> element
use strict;
use warnings;
use Mojo::DOM;
my $xml = q~
<html>
<div>
<p>1</p>
<p>2</p>
<img />
</div>
</html>
~;
my $dom = Mojo::DOM->new($xml);
$dom->at('html > div')->tag('body');
print $dom, "\n";
output
<html>
<body>
<p>1</p>
<p>2</p>
<img>
</body>
</html>

how to create "send email" button on your own google maps website

Hi everybody :) I have a problem. I would like to make it so that when I enter the address. Click on "Send Email" button to send me an email with "http: //" in the form of a link which opens after pressing the Navigator Maps. My code is here.
<?php
echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' dir='ltr' lang='en-us' xml:lang='en-us'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta http-equiv='Content-Language' content='en-us' />
<link rel='icon' type='image/gif' href='http://www.nsc.ee/rssimg/favicon.png' />
<link rel='stylesheet' href='contact.css' type='text/css' />
<link rel='stylesheet' href='info.css' type='text/css' />
<script src='http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places'>
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script src='js/jquery.geocomplete.js'></script>
<script>
$(function(){
$('#geocomplete').geocomplete({
map: '.map_canvas',
details: 'form ',
markerOptions: {
draggable: true
}
});
$('#geocomplete').bind('geocode:dragged', function(event, latLng){
$('input[name=lat]').val(latLng.lat());
$('input[name=lng]').val(latLng.lng());
$('#reset').show();
});
$('#reset').click(function(){
$('#geocomplete').geocomplete('resetMarker');
$('#reset').hide();
return false;
});
$('#find').click(function(){
$('#geocomplete').trigger('geocode');
}).click();
});
</script>
<script>";
echo"
<form>
<table border='0' bgcolor='#1c1a1a'>
<tr>
<td align='center'><input id='geocomplete' type='text' size='48px' placeholder='Palun sisestage aadress' value='' /><form>
<label><font color=#FFFFFF>Pikkus:</font></label>
<input name='lng' type='text' size='20px' value=''>
<label><font color=#FFFFFF>Laius:</font></label>
<input name='lat' type='text' size='20px' value=''>
<a id='reset' href='#' style='display:none;'></a>
</form></td></tr></table>
<table border='0' bgcolor='#1c1a1a'>
<tr>
<td align='center'><div class='map_canvas'></div></td></tr></table></p>
</form>";
?>

GWT getAbsoluteLeft/Top returns wrong value in FF

when i call the getAbsoluteLeft/Top method i always get 0 in firefox. For the IE i get a value which seems to be correct. Are there known problems using these methods ? My problem is that i want to set the position of an element with the absolute position values of another element. Thanks in advance. Edit: Using GWT 2.0.3
kuku
EDIT Testcase:
1. The host page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Web Application Starter Project</title>
<script type="text/javascript" language="javascript" src="samplegwt/samplegwt.nocache.js"></script>
<script type="text/javascript" language="javascript">
function execute() {
var element = document.getElementById("paragraph");
if (element != undefined)
element.style.display = "block";
}
</script>
<STYLE TYPE="text/css">
#paragraph {
display: none;
}
</STYLE>
</head>
<body class="body" onload="execute()">
<div align="center">
<table>
<tr>
<td>
<p id="paragraph">
<input type="text" id="example" value="Foobar" > <img border="0" src="images/some.gif" alt="Test"></p>
</td>
</tr>
</table>
</div>
</body>
</html>
In the onModuleLoad() i simply do this: System.out.println(Document.get().getElementById("paragraph")
.getAbsoluteLeft());
Well as stated in the comments the problem was that the element is not visible which results into 2 different behavoirs for IE and FF.