pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
683 stars 163 forks source link

Crash while trying to attach word .doc file: module 'magic' has no attribute '_libraries #1608

Closed zevv closed 2 weeks ago

zevv commented 1 year ago

Trying to attach a .doc document throws the following error:

INFO:envelope:editable headers: ['From', 'To', 'Subject']
INFO:globals:calling external command: ['vim', '+5', '/tmp/alot.ydvdzjr9.eml']
INFO:globals:open command shell
INFO:envelope:attaching: ['/tmp/attachment.doc']
ERROR:ui:Traceback (most recent call last):
  File "/usr/share/alot/alot/ui.py", line 723, in apply_command
    cmd.apply(self)
  File "/usr/share/alot/alot/commands/envelope.py", line 66, in apply
    envelope.attach(path)
  File "/usr/share/alot/alot/db/envelope.py", line 173, in attach
    part = helper.mimewrap(path, filename, ctype)
  File "/usr/share/alot/alot/helper.py", line 458, in mimewrap
    not libmagic_version_at_least(513)):
  File "/usr/share/alot/alot/helper.py", line 414, in libmagic_version_at_least
    magic_wrapper = magic._libraries['magic']
AttributeError: module 'magic' has no attribute '_libraries'

python3-magic comes from debian upstream and does not seem to have the _libraries; I made a local workaround by changing the offending line into

    if hasattr(magic, 'open') and hasattr(magic, '_libraries'):
pazz commented 1 year ago

I have noticed this exact thing myself recently. Please let me know if/once you have a fix! P

Quoting Ico Doornekamp (2022-09-14 06:49:57)

Trying to attach a .doc document throws the following error:

INFO:envelope:editable headers: ['From', 'To', 'Subject'] INFO:globals:calling external command: ['vim', '+5', '/tmp/alot.ydvdzjr9.eml'] INFO:globals:open command shell INFO:envelope:attaching: ['/tmp/attachment.doc'] ERROR:ui:Traceback (most recent call last): File "/usr/share/alot/alot/ui.py", line 723, in apply_command cmd.apply(self) File "/usr/share/alot/alot/commands/envelope.py", line 66, in apply envelope.attach(path) File "/usr/share/alot/alot/db/envelope.py", line 173, in attach part = helper.mimewrap(path, filename, ctype) File "/usr/share/alot/alot/helper.py", line 458, in mimewrap not libmagic_version_at_least(513)): File "/usr/share/alot/alot/helper.py", line 414, in libmagic_version_at_least magic_wrapper = magic._libraries['magic'] AttributeError: module 'magic' has no attribute '_libraries'

python3-magic comes from debian upstream and does not seem to have the _libraries; I made a local workaround by changing the offending line into

if hasattr(magic, 'open') and hasattr(magic, '_libraries'):

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.*Message ID: @.***>

boutil commented 1 year ago

For reference, this bug has been also reported in Debian by @zevv . https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1019720

boutil commented 10 months ago

I am reading the comment around line 336 of alot/helper.py. The source package python-magic in Debian based on the code of https://github.com/ahupp/python-magic is not using directly the bindings from the file source directly. Rather, the compatibility layer has been now part of upstream python-magic module. The change in the Debian package occured in January 2021, with version 2:0.4.20-1, according to the changelog of Debian's python3-magic package.

Would it make sense to ask a version >= 0.4.20 for the magic python module, and drop the logic in gess_mimetype?