unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Bart Bunting <bart.bunting@ursys.com.au>
To: Brian Sniffen <bts@evenmere.org>, notmuch@notmuchmail.org
Subject: Re: converting attachments to text
Date: Tue, 10 Jan 2017 11:57:54 +1100	[thread overview]
Message-ID: <m21swb20kt.fsf@fiz.local> (raw)
In-Reply-To: <874m1gukfd.fsf@istari.evenmere.org>

Hi Brian,
Thanks so much for this, it has done exactly what I was after!


Kind regards

Bart

Brian Sniffen <bts@evenmere.org> writes:

> Sure!  Here's what I use for docx, and I think it could be adapted to
> pdf with pdftotext or whatever you're already using there.  You need a
> small shell script that reads from STDIN, writes to a file, and calls
> pandoc or pdftotext or whatever, like ~/bin/antiwordx:
>
>     #!/bin/sh
>
>     tmpfile=$(mktemp /tmp/antiwordx.XXXXXX.docx)
>     trap 'rm -f -- "$tmpfile"' INT TERM HUP EXIT
>     cat > "$tmpfile"
>     pandoc --normalize -r docx -w markdown "$tmpfile"
>
> You need a small handler function to call it from Elisp---see attached
> file `inline-docx.el`, which assumed you have both the old `antiword`
> for old-style .doc files and pandoc for new-style `docx`.
>
> I apologize for the roughness of the code; it should probably use
> customizable paths for pandoc and such.
>
> -Brian
>
>
> (defun mm-inline-msword (handle)                                                  
>   (let (text)                                                                     
>     (with-temp-buffer                                                             
>       (mm-insert-part handle)                                                     
>       (call-process-region (point-min) (point-max) "antiword" t t nil "-")        
>       (setq text (buffer-string)))                                                
>     (mm-insert-inline handle text)))                                              
>                                                                                   
> (defun mm-inline-docx (handle)
>   "pandoc --normalize -r docx -w markdown %s"
>   (let (text)                                                                     
>     (with-temp-buffer                                                             
>       (mm-insert-part handle)                                                     
>       (let ((coding-system-for-read 'utf-8))
> 	(call-process-region (point-min) (point-max) "/Users/bts/bin/antiwordx" t t nil))
>       (setq text (buffer-string)))                                                
>     (mm-insert-inline handle text)))                                              
>
> (setq my-inline-mime-tests
>      '(("text/rtf" mm-inline-rtf
>         (lambda
>           (handle)
>           (let
>               ((name
>                 (mail-content-type-get
>                  (mm-handle-disposition handle)
>                  'filename)))
>             (and name
>                  (equal ".rtf"
>                         (substring name -4 nil))))))
>        ("application/x-msword" mm-inline-docx
>         (lambda
>           (handle)
>           (let
>               ((name
>                 (mail-content-type-get
>                  (mm-handle-disposition handle)
>                  'filename)))
>             (and name
>                  (equal ".docx"
>                         (substring name -5 nil))))))
>        ("application/x-msword" mm-inline-msword
>         (lambda
>           (handle)
>           (let
>               ((name
>                 (mail-content-type-get
>                  (mm-handle-disposition handle)
>                  'filename)))
>             (and name
>                  (equal ".doc"
>                         (substring name -4 nil))))))
>        ("application/vnd.openxmlformats-officedocument.wordprocessingml.document" mm-inline-docx identity)
>        ("application/octet-stream" mm-inline-docx
>         (lambda
>           (handle)
>           (let
>               ((name
>                 (mail-content-type-get
>                  (mm-handle-disposition handle)
>                  'filename)))
>             (and name
>                  (equal ".docx"
>                         (substring name -5 nil))))))
>        ("application/octet-stream" mm-inline-msword
>         (lambda
>           (handle)
>           (let
>               ((name
>                 (mail-content-type-get
>                  (mm-handle-disposition handle)
>                  'filename)))
>             (and name
>                  (equal ".doc"
>                         (substring name -4 nil))))))
>        ("application/msword" mm-inline-msword identity)))
>
> (mapcar (lambda (x) (add-to-list 'mm-inlined-types (car x)))
>         my-inline-mime-tests)
>
> (mapcar (lambda (x) (add-to-list 'mm-inline-media-tests x))
>         my-inline-mime-tests)
>
>
> Bart Bunting <bart.bunting@ursys.com.au> writes:
>
>> Hi,
>>
>> Just looking for some pointers.
>>
>> I have to deal with quite a few emails with attachments in either pdf or
>> word format.
>>
>> I'm on a mac so can use applescript or something pdftotext or similar to
>> convert them to text.
>>
>> I'm blind so use emacspeak as my primary interface.  Having an easy way
>> to convert the notmuch attachments to text other than saving to a file
>> and processing them would greatly speed up my workflow.
>>
>> Is there something in existance already to do this sort of thing?
>>
>> I have a little rudimentary lisp skill so can hack something up if
>> someone can give me some pointers on a direction to head in.
>>
>> Any advice appreciated.
>>
>> Kind regards
>>
>> Bart
>>
>> Kind regards
>> Bart
>> -- 
>>
>> Bart Bunting - URSYS
>> PH: 02 87452811
>> Mbl: 0409560005
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> https://notmuchmail.org/mailman/listinfo/notmuch
Bart
-- 

Bart Bunting - URSYS
PH: 02 87452811
Mbl: 0409560005

      reply	other threads:[~2017-01-10  0:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-03  7:27 converting attachments to text Bart Bunting
2017-01-03  7:49 ` Daniel Kahn Gillmor
2017-01-03 17:23 ` Brian Sniffen
2017-01-10  0:57   ` Bart Bunting [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m21swb20kt.fsf@fiz.local \
    --to=bart.bunting@ursys.com.au \
    --cc=bts@evenmere.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).