class OnlyText extends GenericMailet {

    @Override
    public void service(Mail mail) throws MailetException {
        try {
            Object content = mail.getMessage().getContent();
            if (content instanceof Multipart) {
                Multipart mp = (Multipart) content;

                int found = -1;
                int htmlPart = -1;
                int stringPart = -1;
                int[] res = process(mail, (Multipart) content, found, htmlPart, stringPart);
                found = res[0];
                htmlPart = res[1];
                stringPart = res[2];

                if (found < 0 && htmlPart != -1) {
                    setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), html2Text((String) mp.getBodyPart(htmlPart).getContent()), true);
                    found = 1;
                }

                if (found < 0 && stringPart != -1) {
                    setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), null, false);
                    found = 1;
                }


                if (found < 0 && optionsNotextProcessor != null) {
                    mail.setState(optionsNotextProcessor);
                }

            } else if (!(content instanceof String) && optionsNotextProcessor != null) {
                mail.setState(optionsNotextProcessor);
            } else if (mail.getMessage().isMimeType("text/html")) {
                setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true);
            }

        } catch (IOException | MessagingException e) {
            throw new MailetException("Failed fetching text part", e);
        }
    }

}