MOBI Input: Correctly handle MOBI files that have been passed through a DRM removal tool that leaves the DRM fields in the header. Fixes #855732 (Mobi book fails to convert/view; reads ok in Kindle)

This commit is contained in:
Kovid Goyal 2011-09-21 16:35:44 -06:00
parent 39978b361c
commit bb2d522474

View File

@ -135,7 +135,6 @@ class BookHeader(object):
self.length, self.type, self.codepage, self.unique_id, \ self.length, self.type, self.codepage, self.unique_id, \
self.version = struct.unpack('>LLLLL', raw[20:40]) self.version = struct.unpack('>LLLLL', raw[20:40])
try: try:
self.codec = { self.codec = {
1252: 'cp1252', 1252: 'cp1252',
@ -145,8 +144,9 @@ class BookHeader(object):
self.codec = 'cp1252' if not user_encoding else user_encoding self.codec = 'cp1252' if not user_encoding else user_encoding
log.warn('Unknown codepage %d. Assuming %s' % (self.codepage, log.warn('Unknown codepage %d. Assuming %s' % (self.codepage,
self.codec)) self.codec))
if ident == 'TEXTREAD' or self.length < 0xE4 or 0xE8 < self.length \ if (ident == 'TEXTREAD' or self.length < 0xE4 or
or (try_extra_data_fix and self.length == 0xE4): 0xF8 < self.length or # 0xF8 is a correct MOBI header with DRM fields
(try_extra_data_fix and self.length == 0xE4)):
self.extra_flags = 0 self.extra_flags = 0
else: else:
self.extra_flags, = struct.unpack('>H', raw[0xF2:0xF4]) self.extra_flags, = struct.unpack('>H', raw[0xF2:0xF4])