mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 09:52:16 -05:00
fix static analysis warnings and stop using nulls everywhere
This commit is contained in:
parent
e01b1b189f
commit
7fc8767a5c
@ -22,6 +22,9 @@ public interface Part {
|
|||||||
|
|
||||||
String getContentId();
|
String getContentId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of headers of the given name. The array may be empty.
|
||||||
|
*/
|
||||||
String[] getHeader(String name) throws MessagingException;
|
String[] getHeader(String name) throws MessagingException;
|
||||||
|
|
||||||
boolean isMimeType(String mimeType) throws MessagingException;
|
boolean isMimeType(String mimeType) throws MessagingException;
|
||||||
|
@ -49,8 +49,8 @@ class JisSupport {
|
|||||||
|
|
||||||
|
|
||||||
private static String getJisVariantFromMailerHeaders(Message message) throws MessagingException {
|
private static String getJisVariantFromMailerHeaders(Message message) throws MessagingException {
|
||||||
String mailerHeaders[] = message.getHeader("X-Mailer");
|
String[] mailerHeaders = message.getHeader("X-Mailer");
|
||||||
if (mailerHeaders == null || mailerHeaders.length == 0)
|
if (mailerHeaders.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (mailerHeaders[0].startsWith("iPhone Mail ") || mailerHeaders[0].startsWith("iPad Mail "))
|
if (mailerHeaders[0].startsWith("iPhone Mail ") || mailerHeaders[0].startsWith("iPad Mail "))
|
||||||
@ -61,8 +61,8 @@ class JisSupport {
|
|||||||
|
|
||||||
|
|
||||||
private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException {
|
private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException {
|
||||||
String receivedHeaders[] = message.getHeader("Received");
|
String[] receivedHeaders = message.getHeader("Received");
|
||||||
if (receivedHeaders == null)
|
if (receivedHeaders.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (String receivedHeader : receivedHeaders) {
|
for (String receivedHeader : receivedHeaders) {
|
||||||
|
@ -26,7 +26,7 @@ public class MimeHeader {
|
|||||||
|
|
||||||
public String getFirstHeader(String name) {
|
public String getFirstHeader(String name) {
|
||||||
String[] header = getHeader(name);
|
String[] header = getHeader(name);
|
||||||
if (header == null) {
|
if (header.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return header[0];
|
return header[0];
|
||||||
@ -65,9 +65,6 @@ public class MimeHeader {
|
|||||||
values.add(field.getValue());
|
values.add(field.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (values.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return values.toArray(EMPTY_STRING_ARRAY);
|
return values.toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1937,7 +1937,7 @@ public class ImapStore extends RemoteStore {
|
|||||||
*/
|
*/
|
||||||
String[] messageIdHeader = message.getHeader("Message-ID");
|
String[] messageIdHeader = message.getHeader("Message-ID");
|
||||||
|
|
||||||
if (messageIdHeader == null || messageIdHeader.length == 0) {
|
if (messageIdHeader.length == 0) {
|
||||||
if (K9MailLib.isDebug())
|
if (K9MailLib.isDebug())
|
||||||
Log.d(LOG_TAG, "Did not get a message-id in order to search for UID for " + getLogId());
|
Log.d(LOG_TAG, "Did not get a message-id in order to search for UID for " + getLogId());
|
||||||
return null;
|
return null;
|
||||||
|
@ -2362,13 +2362,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||||||
|
|
||||||
// Read In-Reply-To header from draft
|
// Read In-Reply-To header from draft
|
||||||
final String[] inReplyTo = message.getHeader("In-Reply-To");
|
final String[] inReplyTo = message.getHeader("In-Reply-To");
|
||||||
if ((inReplyTo != null) && (inReplyTo.length >= 1)) {
|
if (inReplyTo.length >= 1) {
|
||||||
mInReplyTo = inReplyTo[0];
|
mInReplyTo = inReplyTo[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read References header from draft
|
// Read References header from draft
|
||||||
final String[] references = message.getHeader("References");
|
final String[] references = message.getHeader("References");
|
||||||
if ((references != null) && (references.length >= 1)) {
|
if (references.length >= 1) {
|
||||||
mReferences = references[0];
|
mReferences = references[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2379,7 +2379,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||||||
// Decode the identity header when loading a draft.
|
// Decode the identity header when loading a draft.
|
||||||
// See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
|
// See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
|
||||||
Map<IdentityField, String> k9identity = new HashMap<IdentityField, String>();
|
Map<IdentityField, String> k9identity = new HashMap<IdentityField, String>();
|
||||||
if (message.getHeader(K9.IDENTITY_HEADER) != null && message.getHeader(K9.IDENTITY_HEADER).length > 0 && message.getHeader(K9.IDENTITY_HEADER)[0] != null) {
|
if (message.getHeader(K9.IDENTITY_HEADER).length > 0 && message.getHeader(K9.IDENTITY_HEADER)[0] != null) {
|
||||||
k9identity = IdentityHeaderParser.parse(message.getHeader(K9.IDENTITY_HEADER)[0]);
|
k9identity = IdentityHeaderParser.parse(message.getHeader(K9.IDENTITY_HEADER)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3424,7 +3424,7 @@ public class MessagingController implements Runnable {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
if (message.getHeader(K9.IDENTITY_HEADER) != null) {
|
if (message.getHeader(K9.IDENTITY_HEADER).length > 0) {
|
||||||
Log.v(K9.LOG_TAG, "The user has set the Outbox and Drafts folder to the same thing. " +
|
Log.v(K9.LOG_TAG, "The user has set the Outbox and Drafts folder to the same thing. " +
|
||||||
"This message appears to be a draft, so K-9 will not send it");
|
"This message appears to be a draft, so K-9 will not send it");
|
||||||
continue;
|
continue;
|
||||||
|
@ -1451,7 +1451,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||||||
|
|
||||||
private String getTransferEncoding(Part part) throws MessagingException {
|
private String getTransferEncoding(Part part) throws MessagingException {
|
||||||
String[] contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING);
|
String[] contentTransferEncoding = part.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING);
|
||||||
if (contentTransferEncoding != null && contentTransferEncoding.length > 0) {
|
if (contentTransferEncoding.length > 0) {
|
||||||
return contentTransferEncoding[0].toLowerCase(Locale.US);
|
return contentTransferEncoding[0].toLowerCase(Locale.US);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1812,14 +1812,14 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||||||
// Get the message IDs from the "References" header line
|
// Get the message IDs from the "References" header line
|
||||||
String[] referencesArray = message.getHeader("References");
|
String[] referencesArray = message.getHeader("References");
|
||||||
List<String> messageIds = null;
|
List<String> messageIds = null;
|
||||||
if (referencesArray != null && referencesArray.length > 0) {
|
if (referencesArray.length > 0) {
|
||||||
messageIds = Utility.extractMessageIds(referencesArray[0]);
|
messageIds = Utility.extractMessageIds(referencesArray[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the first message ID from the "In-Reply-To" header line
|
// Append the first message ID from the "In-Reply-To" header line
|
||||||
String[] inReplyToArray = message.getHeader("In-Reply-To");
|
String[] inReplyToArray = message.getHeader("In-Reply-To");
|
||||||
String inReplyTo;
|
String inReplyTo;
|
||||||
if (inReplyToArray != null && inReplyToArray.length > 0) {
|
if (inReplyToArray.length > 0) {
|
||||||
inReplyTo = Utility.extractMessageId(inReplyToArray[0]);
|
inReplyTo = Utility.extractMessageId(inReplyToArray[0]);
|
||||||
if (inReplyTo != null) {
|
if (inReplyTo != null) {
|
||||||
if (messageIds == null) {
|
if (messageIds == null) {
|
||||||
|
@ -560,7 +560,7 @@ public class LocalMessageExtractor {
|
|||||||
// attachments.
|
// attachments.
|
||||||
if (contentDisposition != null &&
|
if (contentDisposition != null &&
|
||||||
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") &&
|
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") &&
|
||||||
part.getHeader(MimeHeader.HEADER_CONTENT_ID) != null) {
|
part.getHeader(MimeHeader.HEADER_CONTENT_ID).length > 0) {
|
||||||
firstClassAttachment = false;
|
firstClassAttachment = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1017,15 +1017,10 @@ public class MessageProvider extends ContentProvider {
|
|||||||
|
|
||||||
// Note: can only delete a message
|
// Note: can only delete a message
|
||||||
|
|
||||||
List<String> segments = null;
|
List<String> segments = uri.getPathSegments();
|
||||||
int accountId = -1;
|
int accountId = Integer.parseInt(segments.get(1));
|
||||||
String folderName = null;
|
String folderName = segments.get(2);
|
||||||
String msgUid = null;
|
String msgUid = segments.get(3);
|
||||||
|
|
||||||
segments = uri.getPathSegments();
|
|
||||||
accountId = Integer.parseInt(segments.get(1));
|
|
||||||
folderName = segments.get(2);
|
|
||||||
msgUid = segments.get(3);
|
|
||||||
|
|
||||||
// get account
|
// get account
|
||||||
Account myAccount = null;
|
Account myAccount = null;
|
||||||
@ -1039,6 +1034,10 @@ public class MessageProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myAccount == null) {
|
||||||
|
throw new IllegalArgumentException("Could not find account with id " + accountId);
|
||||||
|
}
|
||||||
|
|
||||||
// get localstore parameter
|
// get localstore parameter
|
||||||
LocalMessage msg = null;
|
LocalMessage msg = null;
|
||||||
try {
|
try {
|
||||||
@ -1049,14 +1048,16 @@ public class MessageProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
msg = lf.getMessage(msgUid);
|
msg = lf.getMessage(msgUid);
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
Log.e(K9.LOG_TAG, "Unable to retrieve message", e);
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg == null) {
|
||||||
|
throw new IllegalArgumentException("Could not find message with id " + msgUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// launch command to delete the message
|
// launch command to delete the message
|
||||||
if ((myAccount != null) && (msg != null)) {
|
|
||||||
MessagingController controller = MessagingController.getInstance(getContext());
|
MessagingController controller = MessagingController.getInstance(getContext());
|
||||||
controller.deleteMessages(Collections.singletonList(msg), null);
|
controller.deleteMessages(Collections.singletonList(msg), null);
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME return the actual number of deleted messages
|
// FIXME return the actual number of deleted messages
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user