LWP::UserAgent and proxy error - perl

I have a proxy error when using LWP::UserAgent
this is the code:
my $ua = LWP::UserAgent->new();
$ua->proxy( http => $ENV{HTTP_PROXY});
print Dumper($ua);
my $request = new HTTP::Request('GET', $link);
print Dumper( $request );
and this is the dumper for UserAgent
$VAR1 = bless( {
'max_redirect' => 7,
'protocols_forbidden' => undef,
'show_progress' => undef,
'handlers' => {
'response_header' => bless( [
{
'owner' => 'LWP::UserAgent::parse_head',
'callback' => sub { "DUMMY" },
'm_media_type' => 'html',
'line' => 'C:/Perl/lib/LWP/UserAgent.pm:612'
}
], 'HTTP::Config' ),
'request_preprepare' => bless( [
{
'owner' => 'LWP::UserAgent::proxy',
'callback' => sub { "DUMMY" },
'line' => 'C:/Perl/lib/LWP/UserAgent.pm:920'
}
], 'HTTP::Config' )
},
'no_proxy' => [],
'protocols_allowed' => undef,
'local_address' => undef,
'use_eval' => 1,
'requests_redirectable' => [
'GET',
'HEAD'
],
'timeout' => 90,
'def_headers' => bless( {
'user-agent' => 'libwww-perl/5.837'
}, 'HTTP::Headers' ),
'proxy' => {
'http' => 'http://igate:8080'
},
'max_size' => undef
}, 'LWP::UserAgent' );
And this is for the request:
$VAR1 = bless( {
'_content' => '',
'_uri' => bless( do{\(my $o = 'https://some_link')}, 'URI::https' ),
'_headers' => bless( {}, 'HTTP::Headers' ),
'_method' => 'GET'
}, 'HTTP::Request' );
the problem is that the response is an error:
FAIL response, 500 proxy connect failed: PROXY ERROR HEADER, could be non-SSL URL:
HTTP/1.1 503 Service Unavailable
I'm using ActiveState perl 5.10.1 on a WinXP machine
when accessing the link from browser it work
Can somebody help?
Thanks

I've always needed to set https_proxy (rather than just http_proxy) to work with SSL URIs.

Related

Accessing Specific OTRS Dynamic Field value via SOAP

How do I further access this dynamic field value? Upon using below dumper,
print Dumper( $Body->{$ResponseKey} );
The result is :
$VAR1 = {
'Ticket' => {
'Title' => 'TPLUS Service PIC',
'DynamicField' => [
{
'Value' => '43312',
'Name' => 'BugID'
},
{
'Value' => '6',
'Name' => 'OTRSMV'
},
{
'Value' => '6.13',
'Name' => 'OTRSPLV'
},
{
'Value' => 'Dev',
'Name' => 'OTRSUse'
},
{
'Value' => '2018-03-02 00:28:00',
'Name' => 'RefDate'
},
{
'Value' => '0',
'Name' => 'RefNumber'
},
{
'Value' => '',
'Name' => 'StartTime'
}
],
'StateType' => 'open',
'SLAID' => ''
}
};
How can I access the single value of DynamicField->RefDate ? Thanks
my $fields = $Body->{$ResponseKey}{Ticket}{DynamicField};
my ($ref_date) =
map $_->{Value},
grep $_->{Name} eq 'RefDate',
#$fields;
or
my %fields;
$fields{ $_->{Name} } = $fields{ $_->{Value} }
for #{ $Body->{$ResponseKey}{Ticket}{DynamicField} };
my $ref_date = $fields{RefDate};

Perl LWP Unauthorized While Curl Ok

I am attempting to recreate a working CURL command with LWP in Perl and I'm getting a 401 unauthorized error from LWP. The command posts JSON to a specific URL as seen in the code below. The server FQDN, IP, port and path are correct and identical between the curl and Perl as are the credentials and realm. Any help would be appreciated - thank you!
Below is the working syntax in cURL and debug output:
#curl -v -k -u "USERNAME:PASSWORD" -X POST <SERVER_URL> -d '<JSON CONTENT>';
* About to connect() to <SERVER_URL> port 443 (#0)
* Trying <SERVER_IP>... connected
* Connected to <SERVER_URL> (<SERVER_IP>) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
* SSL connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate:
* subject: [REDACTED]
* start date: Apr 21 00:00:00 2016 GMT
* expire date: Apr 21 23:59:59 2019 GMT
* common name: <SERVER_URL>
* issuer: [REDACTED]
* Server auth using Basic with user '<USERNAME>'
> POST <SERVER_PATH> HTTP/1.1
> Authorization: Basic <BASE64-ENCODED USERNAME:PASSWORD>
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: <SERVER_URL>
> Accept: */*
> Content-Length: 144
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Date: Fri, 13 May 2016 13:48:42 GMT
< Server: Apache
< Content-Type: application/json
< Content-Length: 256
<
* Connection #0 to host <SERVER_URL> left intact
* Closing connection #0
Updated Perl code and output per Steffen's suggestion. I corrected an initial quoting error and also added the Accept header to the LWP post command:
use strict;
use warnings;
use LWP::UserAgent;
use Data::Dumper;
my $server_root_with_port = "<FQDN>:443";
my $url = "<SERVER_URL>";
my $realm = "<SERVER_REALM>";
my $json = "<JSON CONTENT>";
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
$ua->credentials($server_root_with_port,$realm,$username=>$password);
$response = $ua->post($url, 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => '*/*', 'Content' => $json);
print Dumper $response;
exit;
$VAR1 = bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '',
'_rc' => '400',
'_headers' => bless( {
'connection' => 'close',
'client-response-num' => 1,
'date' => 'Mon, 16 May 2016 14:18:59 GMT',
'client-ssl-cert-issuer' => '[REDACTED]',
'client-ssl-cipher' => 'AES128-SHA256',
'client-peer' => '<SERVER_IP>:443',
'content-length' => '0',
'::std_case' => {
'client-date' => 'Client-Date',
'client-response-num' => 'Client-Response-Num',
'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',
'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',
'client-ssl-cipher' => 'Client-SSL-Cipher',
'client-peer' => 'Client-Peer',
'client-ssl-socket-class' => 'Client-SSL-Socket-Class'
},
'client-date' => 'Mon, 16 May 2016 14:18:59 GMT',
'client-ssl-cert-subject' => '[REDACTED]',
'server' => 'Apache',
'client-ssl-socket-class' => 'IO::Socket::SSL'
}, 'HTTP::Headers' ),
'_previous' => bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn\'t understand how to supply
the credentials required.</p>
</body></html>
',
'_rc' => '401',
'_headers' => bless( {
'connection' => 'close',
'client-response-num' => 1,
'date' => 'Mon, 16 May 2016 14:18:59 GMT',
'client-ssl-cert-issuer' => '[REDACTED]',
'client-ssl-cipher' => 'AES128-SHA256',
'client-peer' => '<SERVER_IP>:443',
'content-length' => '381',
'::std_case' => {
'client-date' => 'Client-Date',
'client-response-num' => 'Client-Response-Num',
'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',
'title' => 'Title',
'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',
'client-ssl-cipher' => 'Client-SSL-Cipher',
'client-peer' => 'Client-Peer',
'client-ssl-socket-class' => 'Client-SSL-Socket-Class'
},
'client-date' => 'Mon, 16 May 2016 14:18:59 GMT',
'content-type' => 'text/html; charset=iso-8859-1',
'client-ssl-cert-subject' => '[REDACTED]',
'www-authenticate' => 'Basic realm="<SERVER_REALM>"',
'title' => '401 Unauthorized',
'server' => 'Apache',
'client-ssl-socket-class' => 'IO::Socket::SSL'
}, 'HTTP::Headers' ),
'_msg' => 'Unauthorized',
'_request' => bless( {
'_content' => '<JSON_CONTENT>',
'_uri' => bless( do{\(my $o = '<SERVER_URL>')}, 'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/6.15',
'content-type' => 'application/x-www-form-urlencoded',
'accept' => '*/*',
'content-length' => 144,
'::std_case' => {
'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'
}
}, 'HTTP::Headers' ),
'_method' => 'POST',
'_uri_canonical' => $VAR1->{'_previous'}{'_request'}{'_uri'}
}, 'HTTP::Request' )
}, 'HTTP::Response' ),
'_msg' => 'Bad Request',
'_request' => bless( {
'_protocol' => undef,
'_content' => '<JSON_CONTENT>',
'_uri' => bless( do{\(my $o = '<SERVER_URL>')}, 'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/6.15',
'content-type' => 'application/x-www-form-urlencoded',
'accept' => '*/*',
'content-length' => 144,
'authorization' => '<BASE64-ENCODED USERNAME:PASSWORD>',
'::std_case' => {
'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'
}
}, 'HTTP::Headers' ),
'_method' => 'POST',
'_uri_canonical' => $VAR1->{'_request'}{'_uri'}
}, 'HTTP::Request' )
}, 'HTTP::Response' );
Perl Revision #1:
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use Data::Dumper;
my $fqdn_port = "<FQDN>:443";
my $url = "<URL>";
my $realm = "<REALM>";
my $username = "<USERNAME>";
my $password = "<PASSWORD>";
my $json = "<JSON_CONTENT>";
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
#$ua->credentials($fqdn_port,$realm,$username=>$password);
#my $response = $ua->post($url, 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => '*/*', Content => $json);
my $request = HTTP::Request->new('POST',$url);
$request->header('Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => '*/*');
$request->authorization_basic($username,$password);
$request->content($json);
my $response = $ua->request($request);
print Dumper $response;
exit;
$VAR1 = bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '',
'_rc' => '400',
'_headers' => bless( {
'connection' => 'close',
'client-response-num' => 1,
'date' => 'Mon, 16 May 2016 15:41:10 GMT',
'client-ssl-cert-issuer' => '[REDACTED]',
'client-ssl-cipher' => 'AES128-SHA256',
'client-peer' => '<SERVER_IP>:443',
'content-length' => '0',
'::std_case' => {
'client-date' => 'Client-Date',
'client-response-num' => 'Client-Response-Num',
'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',
'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',
'client-ssl-cipher' => 'Client-SSL-Cipher',
'client-peer' => 'Client-Peer',
'client-ssl-socket-class' => 'Client-SSL-Socket-Class'
},
'client-date' => 'Mon, 16 May 2016 15:41:10 GMT',
'client-ssl-cert-subject' => '[REDACTED]',
'server' => 'Apache',
'client-ssl-socket-class' => 'IO::Socket::SSL'
}, 'HTTP::Headers' ),
'_msg' => 'Bad Request',
'_request' => bless( {
'_content' => '<JSON_CONTENT>',
'_uri' => bless( do{\(my $o = '<URL>')}, 'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/6.15',
'content-type' => 'application/x-www-form-urlencoded',
'accept' => '*/*',
'::std_case' => {
'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'
},
'authorization' => 'Basic <BASE64-ENCODED USERNAME:PASSWORD>'
}, 'HTTP::Headers' ),
'_method' => 'POST',
'_uri_canonical' => $VAR1->{'_request'}{'_uri'}
}, 'HTTP::Request' )
}, 'HTTP::Response' );
TL;TR: always use strict !!
$response = $ua->post($url, Content-Type => 'application/json', Content => $json);
You've missed to quote around Content-Type which would have been detected by use strict. This result of this is a strange header 0 you see in the debug output:
'content-type' => 'application/x-www-form-urlencoded',
'0' => 'application/json',
'content-length' => 144,
And this also means that the setting of the content-type is wrong. This together results in the server not accepting your request:
'_rc' => '400',
...
'_msg' => 'Bad Request',
To understand what happens here look at what Perl actually sees in such code:
$ perl -MO=Deparse -e 'my %x = (Content-Type => 1, Foo => 2 )'
my(%x) = ('Content' - 'Type', 1, 'Foo', 2);
This shows that it will interpret the unquoted Content-Type as 'Content' - 'Type'. And since subtraction is not defined for strings they will be cast to an integer, i.e. 0. Which means the result is 0 (0-0).
When using strict you get instead:
perl -Mstrict -e 'my %x = (Content-Type => 1, Foo => 2 )'
Bareword "Content" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
Found a solution - perhaps not the most elegant, but it does the trick. Ended up using HTTP::Request::Common to get around the authorization issue and reversed the quoting on the JSON variable to mitigate the 400 Bad Request and success - getting a correct return from the server! Thanks for the help #steffen_ullrich.
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use Data::Dumper;
my $fqdn_port = "<FQDN>:443";
my $url = "<URL>";
my $realm = "<REALM>";
my $username = "<USERNAME>";
my $password = "<PASSWORD>";
my $json = '<JSON_CONTENT>';
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
my $request = HTTP::Request->new('POST',$url);
$request->header('Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => '*/*');
$request->authorization_basic($username,$password);
$request->content($json);
my $response = $ua->request($request);
print Dumper $response;
exit;
$VAR1 = bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '<RETURN JSON FROM SERVER>',
'_rc' => '200',
'_headers' => bless( {
'connection' => 'close',
'client-response-num' => 1,
'date' => 'Mon, 16 May 2016 16:07:07 GMT',
'client-ssl-cert-issuer' => '[REDACTED]',
'client-ssl-cipher' => 'AES128-SHA256',
'client-peer' => '<SERVER_IP>:443',
'content-length' => '233',
'::std_case' => {
'client-date' => 'Client-Date',
'client-response-num' => 'Client-Response-Num',
'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',
'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',
'client-ssl-cipher' => 'Client-SSL-Cipher',
'client-peer' => 'Client-Peer',
'client-ssl-socket-class' => 'Client-SSL-Socket-Class'
},
'client-date' => 'Mon, 16 May 2016 16:07:07 GMT',
'content-type' => 'application/json',
'client-ssl-cert-subject' => '[REDACTED]',
'server' => 'Apache',
'client-ssl-socket-class' => 'IO::Socket::SSL'
}, 'HTTP::Headers' ),
'_msg' => 'OK',
'_request' => bless( {
'_content' => '<JSON_CONTENT>',
'_uri' => bless( do{\(my $o = '<URL>')}, 'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/6.15',
'content-type' => 'application/x-www-form-urlencoded',
'accept' => '*/*',
'::std_case' => {
'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'
},
'authorization' => 'Basic <BASE64-ENCODED USERNAME:PASSWORD>'
}, 'HTTP::Headers' ),
'_method' => 'POST',
'_uri_canonical' => $VAR1->{'_request'}{'_uri'}
}, 'HTTP::Request' )
}, 'HTTP::Response' );

Looking of a value in blessed hash

I am a begginer in Perl an i am trying to get à value from à blessed hash.
The value is ip adresses, i tried that with no success
print $vm->guest->ipStack->dnsConfig->ipAddress;
print $vm->guest->ipStack{dnsConfig}{ipAddress};
$VAR1 = [
bless( {
"ipRouteConfig" => bless( {
"ipRoute" => [
bless( {
"gateway" => bless( {
"device" => 0,
"ipAddress" => "10.*******"
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "0.0.0.0",
"prefixLength" => 0
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"network" => "1***********",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"prefixLength" => 23
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 32,
"network" => "10**************",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 32,
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "1***********5"
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 4,
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "224.0.0.0"
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' ),
"network" => "255.255.255.255",
"prefixLength" => 32
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 64,
"network" => "fe80::",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 128,
"network" => "fe80::",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' ),
bless( {
"prefixLength" => 8,
"network" => "ff00::",
"gateway" => bless( {
"device" => 0
}, 'NetIpRouteConfigInfoGateway' )
}, 'NetIpRouteConfigInfoIpRoute' )
]
}, 'NetIpRouteConfigInfo' ),
"dnsConfig" => bless( {
"dhcp" => 0,
"searchDomain" => [
"france"
],
"hostName" => "HOST",
"ipAddress" => [
"10.60****",
"10.6*****",
"10.8*****"
],
"domainName" => "france"
}, 'NetDnsConfigInfo' )
}, 'GuestStackInfo' )
]
Whatever you have dumped is an array, not a hash. You need to show the call to Dumper for us to help you properly
Also, since this is a structure of blessed objects, you should be using their methods to access information, not going by the "back door" and messing with the data structure directly. Unfortunately GuestStackInfo and NetDnsConfigInfo are VMware classes and not one of the standard Perl types so I can't suggest what method calls may be appropriate
Here are some notes
The structure referred to by $VAR1 is a one-element array containing a GuestStackInfo object
The GuestStackInfo object contains a NetIpRouteConfigInfo object and a NetDnsConfigInfo object. I assume you are interested in the latter as you say "The value is ip adresses", and the nearest hash key is ipAddress in the NetDnsConfigInfo object
The ipAddress element is reference to an array of IP address-like strings
To access this array you would write
my $addresses = $VAR1->[0]{dnsConfig}{ipAddress};
and then to print them all out, use
print "$_\n" for #$addresses;
But please take note of my initial comments -- you should be using method calls and not poking around the data structure like this. Is there any documentation for those classes?

Append an element to an already existing SOAP::Data complex type

I'm very new to SOAP, PERL and pretty much everything else I've been asked to do so I'm hoping someone can point me in the right direction.
I've implemented a simple WCF solution and I've written a PERL client which passes a "complex data structure" to the solution using SOAP::lite and SOAP::Data. All this works very well so far, WCF solution see's the array as an array and I'm able to iterate through the array on the server side just fine.
However, I'm having an issue trying to append a data element to the array on the PERL side. I have the following code, which builds the array I need, but I need to append a few lines to the array later on in the code and I can't figure out how to that.
# build array of values
my $data= SOAP::Data->new
(name => 'array', value =>
[
SOAP::Data->new(name => 'elem:string', value => 'firststring'),
SOAP::Data->new(name => 'elem:string', value => 'secondstring'),
SOAP::Data->new(name => 'elem:string', value => 'thridstring')
]
)
->attr
(
{ 'xmlns:elem' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays','xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance'}
);
# create a new element
my $elem1 = SOAP::Data->new(name => 'elem:string', value => 'addedstring');
# try to add the element
push(#{$data->{array}},$elem1);
#.... send, catch, print.. bla bla bla
The code I have runs, and the WCF service see's the array just fine, but the $elem1 value is never actually appended to the SOAP envelope.
Any help is GREATLY appreciated...
Take a look at what $data is using Data::Dumper, you get this
$VAR1 = bless( {
'_attr' => {
'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:elem' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
},
'_signature' => [],
'_name' => 'array',
'_value' => [
[
bless( {
'_value' => [
'firststring'
],
'_name' => 'string',
'_prefix' => 'elem',
'_signature' => [],
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_value' => [
'secondstring'
],
'_name' => 'string',
'_signature' => [],
'_prefix' => 'elem',
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_attr' => {},
'_value' => [
'thridstring'
],
'_name' => 'string',
'_signature' => [],
'_prefix' => 'elem'
}, 'SOAP::Data' )
]
]
}, 'SOAP::Data' );
There is no $data->{array}
A look at the documentation for SOAP::Data, says you should use $data->value to access the array you created.
push #{ $data->value }, $elem1;
print Dumper $data->value;
yields
$VAR1 = [
bless( {
'_attr' => {},
'_prefix' => 'elem',
'_value' => [
'firststring'
],
'_name' => 'string',
'_signature' => []
}, 'SOAP::Data' ),
bless( {
'_signature' => [],
'_name' => 'string',
'_value' => [
'secondstring'
],
'_prefix' => 'elem',
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_name' => 'string',
'_signature' => [],
'_value' => [
'thridstring'
],
'_prefix' => 'elem',
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_attr' => {},
'_prefix' => 'elem',
'_value' => [
'addedstring'
],
'_name' => 'string',
'_signature' => []
}, 'SOAP::Data' )
];
Thanks Gabs00,
push $data->value, $elem1; worked beautifully

Stuck trying to access hash value

I inherited a script and I need to be able to access some data from a hash. I want to be able to access the MB_Path value from the following.
$VAR1 = bless(
{
'ME_Parts' => [
bless(
{
'ME_Bodyhandle' => bless(
{
'MB_Path' => '/tmp/msg-15072-1.txt'
},
'MIME::Body::File'
),
'ME_Parts' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: text/plain; charset="us-ascii"',
'Content-Transfer-Encoding: quoted-printable'
],
'mail_hdr_hash' => {
'Content-Type' => [
\$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}
{'mail_hdr_list'}[0]
],
'Content-Transfer-Encoding' => [
\$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}
{'mail_hdr_list'}[1]
]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
},
'MIME::Entity'
),
bless(
{
'ME_Bodyhandle' => bless(
{
'MB_Path' => '/tmp/msg-15072-2.html'
},
'MIME::Body::File'
),
'ME_Parts' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: text/html;charset="us-ascii"',
'Content-Transfer-Encoding: quoted-printable'
],
'mail_hdr_hash' => {
'Content-Type' => [
\$VAR1->{'ME_Parts'}[1]{'mail_inet_head'}
{'mail_hdr_list'}[0]
],
'Content-Transfer-Encoding' => [
\$VAR1->{'ME_Parts'}[1]{'mail_inet_head'}
{'mail_hdr_list'}[1]
]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
},
'MIME::Entity'
)
],
'ME_Epilogue' => [],
'ME_Preamble' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: multipart/alternative;boundary="----_=_NextPart_002_01CEB949.DC6B0180"'
],
'mail_hdr_hash' => {
'Content-Type' =>
[ \$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[0] ]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
'MIME::Entity'
);
I thought I could simply do the following
print $ent->parts->($i)->{ME_Bodyhandle}->{MB_Path};
However when I do that I get and error that the value is not initialized. But when I do dump of just $ent->parts->($i) I get the above code.
I am just stuck on this one.
Thanks,
Leo C
You don't have a hash, you have an object (which happens to be implemented as a hash). That's why the Data::Dumper output keeps saying bless(...). You shouldn't be poking into its internals.
I think you're looking for
$ent->parts($i)->bodyhandle->path;
Until you have exhausted the possibilities of the documentation, there is no excuse for dumping the underlying data structure that represents a Perl object and hard-coding access to its components. The rules of encapsulation apply to Perl object-oriented programming just as much as any other language.
The documentation for
MIME::Entity
and
MIME::Body
is quite clear, and the code you need is something like this
for my $part ($ent->parts) {
my $path = $part->bodyhandle->path;
print $path, "\n";
}
output
/tmp/msg-15072-1.txt
/tmp/msg-15072-2.html
This:
print $ent->parts->($i)->{ME_Parts}->[$i]->{ME_Bodyhandle}->{MB_Path};