for (Part part : parts) {
if (part instanceof PlainTextPart) {
String longText = ((PlainTextPart) part).getText();
if (allPartsLength < cutOffLength) {
if ((allPartsLength + longText.length()) > cutOffLength) {
shortenedParts.add(new PlainTextPart(longText.substring(0, cutOffLength - allPartsLength) + "…"));
} else {
shortenedParts.add(part);
}
}
allPartsLength += longText.length();