Read embedded inline image from email as html - jakarta-mail

I tried to read email using IMAP connection. I am getting emails as html content. When i receive an email with body containing image. i am fail to get the image from email body.
The html output is follows.
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
#font-face
{font-family:Cambria;
panose-1:2 4 5 3 5 4 6 3 2 4;}
#font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
#font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
#page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The body parts <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><i><span lang="EN-GB" style="font-size:10.0pt;font-family:"Cambria","serif";color:#365F91">Regards</span></i><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#365F91">,</span></i><span lang="EN-IN" style="color:#365F91"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="color:#365F91"> </span><span lang="EN-IN" style="color:#365F91"><o:p></o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D">Amith K Bharathan</span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D">Software Engineer</span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D"> </span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal">
<span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D">
**<img width="110" height="61" id="Picture_x0020_1" src="cid:image001.png#01D190D9.38FE7C00" alt="Description: Description: Description: Description: tstlogo">**
</span><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D">TTT Software & Systems India Pvt. Ltd.</span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D"> Infopark, Kakkanad-682 030</span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><b><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D">Mob :</span></i></b><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D"> +91 99957</span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><b><i><span style="font-size:10.0pt;font-family:"Cambria","serif";color:#17365D">Email :</span></i></b><i><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#17365D">
<span style="color:#17365D">amith.bharathan#tst.co.in</span></span></i><span lang="EN-IN" style="color:#17365D"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>
my code snippet is:
private String getTextFromMimeMultipart(
MimeMultipart mimeMultipart) throws Exception{
String result = "";
int count = mimeMultipart.getCount();
System.out.println("____________START______GET MULTI PART"+count);
for (int i = 0; i < count; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
System.out.println("11111111111111");
result = result + "\n" + bodyPart.getContent();
//System.out.println("RESULT "+result);
// break; // without break same text appears twice in my tests
} if (bodyPart.isMimeType("text/html")) {
System.out.println("2222222");
String html = (String) bodyPart.getContent();
System.out.println("22 bodypart "+bodyPart.getContentType());
result = result + "\n >>> " + org.jsoup.Jsoup.parse(html).text();
} if (bodyPart.getContent() instanceof MimeMultipart){
result = result + getTextFromMimeMultipart((MimeMultipart)bodyPart.getContent());
System.out.println("3333333333333"+(MimeMultipart)bodyPart.getContent());
Multipart multiPart = (MimeMultipart)bodyPart.getContent();
System.out.println("multipart COUNT "+multiPart.getCount());
for (int v = 0; v < multiPart.getCount(); v++) {
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(v);
System.out.println("PART ENCODING 111"+part.getEncoding()+"DISPOSITION "+part.getDisposition());
// downloadFile("fl"+v, part) ;
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
downloadFile("fl"+v, part) ;
} if (Part.INLINE.equalsIgnoreCase(part.getDisposition())) {
System.out.println("_________________INLINE___________");
}
if(part.getDisposition() == null){
System.out.println("INLINE FILE NAME "+part.getFileName());
//downloadFile("fl"+v, part) ;
}
}
}
}
System.out.println("____________END___________"+result);
return result;
}
O/P:
____________START______GET MULTI PART2
2222222
22 bodypart text/html; charset=us-ascii
____________END___________
  The body parts   Regards,   Amith K  Bharathan Software Engineer   TST Software & Systems India Pvt. Ltd. Infopark, Kakkanad-682 030 Mob   : +91 99947 Email : amith.bharathan#tst.co.in    
MULTI PART 2
INLINE IMAGE FILLLLL NAMEEEE null I/P com.sun.mail.imap.IMAPInputStream#75b3adecMIME

If you get a multipart message you go through the parts. You handle text/plain parts, text/html parts, and multipart parts. If one of the parts of the top level message is a multipart, you look for images in that sub-multipart. But you never look for images in the top level multipart. Add an "else" clause to the top level "if" statement and you'll see what you're missing.
You've made some assumptions about the structure of a MIME message that aren't true in general.

Related

Atmosphere.js package, angular-templates, throws error on less than operator in my binding

The Error being thrown
=> Errors prevented startup:
While processing files with angular-templates (for target web.browser):
client/templates/rcalendar/day.html:7: Expected tag name after `<`
... {{$index<12?($index === 0?12:...
^
client/templates/rcalendar/week.html:16: Expected tag name after `<`
... {{$index<12?($index === 0?12:...
The offending HTML
<td class="calendar-cell">
<div class="add_event_shade" style="height:100%;" ng-if="!tm.events" ng-show"clickCount" on-touch="hourTouch($event)">
<p style="display:none;">+ New event</p>
<p style="display:none;">{{$index<12?($index === 0?12:$index)+':00 am':($index === 12?$index:$index-12)+':00 pm'}}</p>
</div>
<div ng-class="{'calendar-event-wrap': tm.events}" ng-show="tm.events">
<div ng-repeat="displayEvent in tm.events"
class="calendar-event"
ng-click="eventSelected({event:displayEvent.event})"
ng-style="{left: 100/displayEvent.overlapNumber*displayEvent.position+'%', width: 100/displayEvent.overlapNumber+'%', top: displayEvent.event.startTimeOffset+'%', height: 37*(displayEvent.event.totalApptTime)+'px'}">
<div class="calendar-event-inner" style="white-space: pre-wrap; font-weight: bold">{{displayEvent.event.title}}</div>
</div>
</div>
</td>
How can I set conditionals in my bindings like this?
I think you have to do something like this :
<p style="display:none;">
{{($index < 12 && $index === 0)? 12 : $index}}:00 am
{{$index === 12? $index : ($index - 12)}}:00 pm
</p>
But be careful, you put a display:none in the p tag.
Edit: As discussed in the comments, to avoid the error given by angular-template we can call a function from the controller instead of evaluating the expression in the p tag
<p>{{getTime($index)}}</p>

ng-class expression not working with parameter coming from httpresponse

I have a servlet that returns a JSON object with a parameter named "valoracion" and I want to use it for a span label to be a css class with the name of the value associated to that parameter. This I want to do it to show a .gif in a different way depending on this class. I'm using AngularJS, btw.
This is the js code from the "novedades" page controller:
angular.module('myApp')
.controller('novedadesCtrl', [ '$scope','auth', 'novedadesService', function($scope,auth,novedadesService){
$scope.mostrar = ["Comentarios","Valoraciones"];
$scope.novedades = "Comentarios";
$scope.novedadesComentarios;
$scope.novedadesValoraciones;
$scope.cogerNovedades = function(){
debugger;
novedadesService.novedades( auth.idUser(), function(comentarios,valoraciones) {
$scope.novedadesComentarios = comentarios;
console.log(valoraciones);
$scope.novedadesValoraciones = valoraciones;
});
};
$scope.cogerNovedades();
}]);
novedadesService.novedades is a factory that sends a POST request to the servlet and returns the same JSON returned by the servlet. This is an example of the aforementioned JSON:
idJuego: 0
idUsuario: 500
juego: "Star Wars: The Old Republic"
nombreApellidos: "Gregorio de Miguel"
nombreUsuario: "Goyo"
valoracion: "cuatroEstrella"
This other one is the html code for that page:
<div class="container" id="cuerpo">
<h1 class="theme-color-text font">Novedades</h1>
<div class="row form-inline">
<div class="form-group" style="float: right;">
<label for="mostrar">Mostrar: </label>
<select id="mostrar" class="form-control" ng-model="novedades"
ng-options="x for x in mostrar">
</select>
</div>
</div>
<!-- lista de novedades de comentarios -->
<div ng-if="novedades == 'Comentarios'" class="row">
<ul class="list-group" id="novedades">
<li class="list-group-item" ng-repeat="comentario in novedadesComentarios">
{{comentario.nombreUsuario}}
({{comentario.nombreApellidos}}) ha comentado el juego
{{comentario.juego}}</li>
</ul>
</div>
<!-- lista de novedades de valoraciones -->
<div ng-if="novedades == 'Valoraciones'" class="row">
<ul class="list-group" id="novedades">
<li class="list-group-item" ng-repeat="valoracion in novedadesComentarios">
{{valoracion.nombreUsuario}}
({{valoracion.nombreApellidos}}) ha valorado el juego
{{valoracion.juego}}
con <span ng-class="{{valoracion.valoracion}}"></span></li>
</ul>
</div>
This is the part where I have the problem:
<span ng-class="{{valoracion.valoracion}}"></span>
The following is an example from the css we want the page to show:
.cuatroEstrella{
display: inline-block;
margin-bottom: -10px;
width: 100px;
height: 30px;
background: url("../img/valoracion.gif") 0 -262px;
}
Here you have a screenshot from the page. You can see the problem in the developers console.
I appreciate any help you can provide on this issue.
Don't need to use the {{}}, just like this :
<span ng-class="valoracion.valoracion"></span>
Bad copy/paste ;). You are iterating through 'novedadesComentarios' instead through 'novedadesValoraciones'. You are doing this:
<li class="list-group-item" ng-repeat="valoracion in novedadesComentarios">
{{valoracion.nombreUsuario}}
({{valoracion.nombreApellidos}}) ha valorado el juego
{{valoracion.juego}}
con <span ng-class="{{valoracion.valoracion}}"></span>
</li>
And I think you want to do this:
<li class="list-group-item" ng-repeat="valoracion in novedadesValoraciones">
{{valoracion.nombreUsuario}}
({{valoracion.nombreApellidos}}) ha valorado el juego
{{valoracion.juego}}
con <span ng-class="valoracion.valoracion"></span>
</li>
Update
I had forgotten to say that you still have to do what #Mike Vranckx said and remove the {{}}

How i add text in iframe in e2e testing Protractor

how i add text in p tag?
<div id="cke_1_contents" class="cke_contents cke_reset" role="presentation" style="height: 350px;"><span id="cke_44" class="cke_voice_label">Press ALT 0 for help</span>
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, editor2" aria-describedby="cke_106" tabindex="0" allowtransparency="true">
<html lang="en" dir="ltr">
<head>
<body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="true">
<p>
<br type="_moz">
</p>
</body>
</html>
</iframe>
</div>
i use this code but the give error
var p = element(by.css('.cke_editable p'));
p.sendKeys('This is a peragraph tag');
You'll need to switch to the iframe's page context to do this:
browser.switchTo().frame($('.cke_wysiwyg_frame'))
var p = element(by.css('.cke_editable p'));
p.sendKeys('This is a peragraph tag');
// switch back to the "parent page" context
browser.switchTo().defaultContent()

Convert append from in javascript to AngularJS

I created this simple game where a user is trying to guess a number. I want to use AngularJS frameworks but I am lacking on the basic concepts. For example the first part of my code is a a function that will be used to append the guess to a list of guesses. My issue here is I am not sure how to append to a scope in AngularJS. Here is that part of my original code
var numOfAttempts = 6;
var numOfGuesses = 0;
var numberToGuess = "Three";
function listWordsUsed(numberAttempted)
{
var userTrials = $('#userGuesses');
var divisor = $("<p id ='line'><div class='answers'>" + numberAttempted + "</div></p>");
divisor.hide().appendTo(userTrials).fadeIn(6000);
return;
} //End of function listWordsUsed(numberAttempted)
I know that I will have to make my variables scopes in order to be used by my aplication, like this
$scope.numOfAttempts = 6;
$scope.numOfGuesses = 0;
$scope.numberToGuess = "Three";
However I am not sure how to append to a scope variable in AngularjS. Any suggestions? Hints? By the way here is my HTML as I started setting it up.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Guess the Number in AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script src="js/controllers/app.js" type="text/javascript"></script>
<script src="js/controllers/maincontroller.js" type="text/javascript"></script>
</head>
<body>
<div id='content' ng-app='numberApp' ng-controller='numberController'>
<p>
<header>
<h2 align="center">What number am I thinking of?</h2>
</header>
<h3>Enter the number:</h3>
<table>
<td><input type='text' ng-model='guestGuess' />
<p>This is: {{guestGuess}}</p>
<p>This is: {{magicWord}}</p>
</td>
<td id="guessBox"><input type="submit" id="guessButton" value="Guess" /></td>
</table>
</p>
<p>
<h3>Your guesses so far are: </h3>
<p style="text-align:center;" id="numberGuesses"></p>
<p id="guessesUsed">You have guessed: <span id="userAttempts"></span> times out six(6) chances.</p>
<p id="guessesLeft">You have <span id="attemptsLeft"></span> guesses left.</p>
</p>
</div>
</div>
</body>
Here's a Plunkr
Basically you just build an array of the guesses you list it with ng-repeat. The rest is just count with .length(), and then do basic math right in the interpolated HTML.
<div ng-controller="numberController">
<h3>Enter the number:</h3>
<input type="text" ng-model="guess" />
<p>Guess is: {{guess}}</p>
<button ng-click="addGuess()">Guess</button>
<h3>Your guesses so far are: <span>{{guessed}}</span></h3>
<ul>
<li ng-repeat="g in guesses">
<p>{{g}}</p>
</li>
</ul>
<p>You have guessed: <b>{{guessed}}</b> times out six({{allowed}}) chances.</p>
<p>You have <b>{{allowed - guessed}}</b> guesses left.</p>
</div>

ng-pluralize, Add the bootstrap class

In my code, based on the result, I am displaying the message using
<span ng-if="data.length >= 1" class="badge badge-success">{{data.length}}</span>
<span ng-if="data.length == 0" class="badge badge-error">{{data.length}}</span>
2 Doubts :
First:
<ng-pluralize count="data.length" offset=2
when="{'0' : 'No driver. :-(',
'1' : ' driver !',
'2' : ' {{data[0].Driver.givenName}}, {{data[1].Driver.givenName}} driver !',
'other': ' {{data[0].Driver.givenName}}, {{data[1].Driver.givenName}} and {} others.'}">
</ng-pluralize>
Above code displays :
Found: 13 Sebastian, Fernando and 11 others.
I know that the first green oval is from <span /> tag with class "badge badge-success",
What if I Want to color the other integer value (11) to
<span class="badge badge-warning">11</span>
I mean I should get the result like :
Second:
<!--span ng-class="{ 'badge badge-success' : data.length > 1, badge badge-error }"> {{data.length}}</span--> //Why this is not working ?
Anyways, This I have achieved by using `ng-if` by using 2 span tags, but just for my understanding what is wrong in this span tag conditioning.
I chose an Alternative solution, Used ng-switch
<div ng-switch="data.length">
<div ng-switch-when="0">No drivers. :-(</div>
<div ng-switch-when="1">1 driver!</div>
<div ng-switch-when="2">{{data[0].Driver.givenName}} and {{data[1].Driver.givenName}} driver !</div>
<div ng-switch-default>{{data[0].Driver.givenName}}, {{data[1].Driver.givenName}} and
<span class="badge badge-info">{{data.length - 2}}</span> other !</div>
</div>,
Now it works fines, as I was except for

Resources