diff --git a/src/calibre/ebooks/mobi/reader/mobi6.py b/src/calibre/ebooks/mobi/reader/mobi6.py index bba572f8dd..eef167655e 100644 --- a/src/calibre/ebooks/mobi/reader/mobi6.py +++ b/src/calibre/ebooks/mobi/reader/mobi6.py @@ -29,6 +29,10 @@ class TopazError(ValueError): pass +class KFXError(ValueError): + pass + + class MobiReader(object): PAGE_BREAK_PAT = re.compile( r'<\s*/{0,1}\s*mbp:pagebreak((?:\s+[^/>]*){0,1})/{0,1}\s*>\s*(?:<\s*/{0,1}\s*mbp:pagebreak\s*/{0,1}\s*>)*', @@ -71,6 +75,8 @@ class MobiReader(object): raw = stream.read() if raw.startswith('TPZ'): raise TopazError(_('This is an Amazon Topaz book. It cannot be processed.')) + if raw.startswith(b'\xeaDRMION\xee'): + raise KFXError(_('This is an Amazon KFX book. It cannot be processed.')) self.header = raw[0:72] self.name = self.header[:32].replace('\x00', '') @@ -890,5 +896,3 @@ def test_mbp_regex(): ans = MobiReader.PAGE_BREAK_PAT.sub(r'\1', raw) if ans != m: raise Exception('%r != %r for %r'%(ans, m, raw)) - -