Handle incoming attachments with missing MIME type.

pull/2/head
Matthew Chen 6 years ago
parent 14e7274c3d
commit fed4899c8d

@ -116,9 +116,17 @@ NS_ASSUME_NONNULL_BEGIN
OWSFailDebug(@"Invalid attachment key."); OWSFailDebug(@"Invalid attachment key.");
return nil; return nil;
} }
if (attachmentProto.contentType.length < 1) { NSString *_Nullable fileName = attachmentProto.fileName;
OWSFailDebug(@"Invalid attachment content type."); NSString *_Nullable contentType = attachmentProto.contentType;
return nil; if (contentType.length < 1) {
OWSLogError(@"Invalid attachment content type.");
NSString *_Nullable fileExtension = [fileName pathExtension].lowercaseString;
if (fileExtension.length > 0) {
contentType = [MIMETypeUtil mimeTypeForFileExtension:fileExtension];
}
if (contentType.length < 1) {
contentType = OWSMimeTypeApplicationOctetStream;
}
} }
// digest will be empty for old clients. // digest will be empty for old clients.
@ -151,8 +159,8 @@ NS_ASSUME_NONNULL_BEGIN
key:attachmentProto.key key:attachmentProto.key
digest:digest digest:digest
byteCount:attachmentProto.size byteCount:attachmentProto.size
contentType:attachmentProto.contentType contentType:contentType
sourceFilename:attachmentProto.fileName sourceFilename:fileName
caption:caption caption:caption
albumMessageId:albumMessageId albumMessageId:albumMessageId
attachmentType:attachmentType attachmentType:attachmentType

Loading…
Cancel
Save