Search in sources :

Example 1 with NonNull

use of androidx.annotation.NonNull in project k-9 by k9mail.

the class PgpMessageBuilder method createOpenPgpDataSourceFromBodyPart.

@NonNull
private OpenPgpDataSource createOpenPgpDataSourceFromBodyPart(final MimeBodyPart bodyPart, final boolean writeBodyContentOnly) throws MessagingException {
    return new OpenPgpDataSource() {

        @Override
        public void writeTo(OutputStream os) throws IOException {
            try {
                if (writeBodyContentOnly) {
                    Body body = bodyPart.getBody();
                    InputStream inputStream = body.getInputStream();
                    IOUtils.copy(inputStream, os);
                } else {
                    bodyPart.writeTo(os);
                }
            } catch (MessagingException e) {
                throw new IOException(e);
            }
        }
    };
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) InputStream(java.io.InputStream) EOLConvertingOutputStream(com.fsck.k9.mail.filter.EOLConvertingOutputStream) OutputStream(java.io.OutputStream) OpenPgpDataSource(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource) IOException(java.io.IOException) TextBody(com.fsck.k9.mail.internet.TextBody) Body(com.fsck.k9.mail.Body) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) NonNull(androidx.annotation.NonNull)

Example 2 with NonNull

use of androidx.annotation.NonNull in project k-9 by k9mail.

the class PgpMessageBuilder method buildOpenPgpApiIntent.

@NonNull
private Intent buildOpenPgpApiIntent(boolean shouldSign, boolean shouldEncrypt, boolean encryptToSelfOnly, boolean isPgpInlineMode) {
    Intent pgpApiIntent;
    Long openPgpKeyId = cryptoStatus.getOpenPgpKeyId();
    if (shouldEncrypt) {
        pgpApiIntent = new Intent(shouldSign ? OpenPgpApi.ACTION_SIGN_AND_ENCRYPT : OpenPgpApi.ACTION_ENCRYPT);
        long[] selfEncryptIds = { openPgpKeyId };
        pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, selfEncryptIds);
        if (!encryptToSelfOnly) {
            pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
        // pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
        }
    } else {
        pgpApiIntent = new Intent(isPgpInlineMode ? OpenPgpApi.ACTION_SIGN : OpenPgpApi.ACTION_DETACHED_SIGN);
    }
    if (shouldSign) {
        pgpApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, openPgpKeyId);
    }
    pgpApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    return pgpApiIntent;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NonNull(androidx.annotation.NonNull)

Example 3 with NonNull

use of androidx.annotation.NonNull in project k-9 by k9mail.

the class BodyTextExtractor method getBodyTextFromMessage.

/**
 * Fetch the body text from a messagePart in the desired messagePart format. This method handles
 * conversions between formats (html to text and vice versa) if necessary.
 */
@NonNull
public static String getBodyTextFromMessage(Part messagePart, SimpleMessageFormat format) {
    Part part;
    if (format == SimpleMessageFormat.HTML) {
        // HTML takes precedence, then text.
        part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
        if (part != null) {
            Timber.d("getBodyTextFromMessage: HTML requested, HTML found.");
            return getTextFromPartOrEmpty(part);
        }
        part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
        if (part != null) {
            Timber.d("getBodyTextFromMessage: HTML requested, text found.");
            String text = getTextFromPartOrEmpty(part);
            return HtmlConverter.textToHtml(text);
        }
    } else if (format == SimpleMessageFormat.TEXT) {
        // Text takes precedence, then html.
        part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
        if (part != null) {
            Timber.d("getBodyTextFromMessage: Text requested, text found.");
            return getTextFromPartOrEmpty(part);
        }
        part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
        if (part != null) {
            Timber.d("getBodyTextFromMessage: Text requested, HTML found.");
            String text = getTextFromPartOrEmpty(part);
            return HtmlConverter.htmlToText(text);
        }
    }
    // If we had nothing interesting, return an empty string.
    return "";
}
Also used : Part(com.fsck.k9.mail.Part) NonNull(androidx.annotation.NonNull)

Example 4 with NonNull

use of androidx.annotation.NonNull in project k-9 by k9mail.

the class AutocryptGossipHeaderParser method parseAllAutocryptGossipHeaders.

@NonNull
private List<AutocryptGossipHeader> parseAllAutocryptGossipHeaders(String[] headers) {
    ArrayList<AutocryptGossipHeader> autocryptHeaders = new ArrayList<>();
    for (String header : headers) {
        AutocryptGossipHeader autocryptHeader = parseAutocryptGossipHeader(header);
        if (autocryptHeader == null) {
            Timber.e("Encountered malformed autocrypt-gossip header - skipping!");
            continue;
        }
        autocryptHeaders.add(autocryptHeader);
    }
    return autocryptHeaders;
}
Also used : ArrayList(java.util.ArrayList) ByteString(okio.ByteString) NonNull(androidx.annotation.NonNull)

Example 5 with NonNull

use of androidx.annotation.NonNull in project AndroidPicker by gzu-liyujiang.

the class TextAddressParser method parseData.

@NonNull
@Override
public List<ProvinceEntity> parseData(@NonNull String text) {
    provinces.clear();
    String[] fullCodeAndNames = text.split(";");
    for (String fullCodeAndName : fullCodeAndNames) {
        String[] codeAndName = fullCodeAndName.split(",");
        if (codeAndName.length != 2) {
            continue;
        }
        String code = codeAndName[0];
        String name = codeAndName[1];
        if (code.startsWith("0000", 2)) {
            // 省份
            ProvinceEntity province = new ProvinceEntity();
            province.setCode(code);
            province.setName(name);
            province.setCityList(new ArrayList<>());
            provinces.add(province);
        } else if (code.startsWith("00", 4)) {
            // 地市
            ProvinceEntity province = findProvinceByCode(code.substring(0, 2));
            if (province != null) {
                CityEntity city = new CityEntity();
                city.setCode(code);
                city.setName(name);
                city.setCountyList(new ArrayList<>());
                province.getCityList().add(city);
            }
        } else {
            // 区县
            CityEntity city = findCityByCode(code.substring(0, 2), code.substring(2, 4));
            if (city != null) {
                CountyEntity county = new CountyEntity();
                county.setCode(code);
                county.setName(name);
                city.getCountyList().add(county);
            }
        }
    }
    return provinces;
}
Also used : CountyEntity(com.github.gzuliyujiang.wheelpicker.entity.CountyEntity) ArrayList(java.util.ArrayList) CityEntity(com.github.gzuliyujiang.wheelpicker.entity.CityEntity) ProvinceEntity(com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1196 View (android.view.View)191 ArrayList (java.util.ArrayList)153 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)117 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)76 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62