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);
}
}
};
}
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;
}
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 "";
}
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;
}
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;
}
Aggregations