Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'messages.': 0.05; 'tree': 0.05; 'binary': 0.07; 'suggestions,': 0.07; 'complicate': 0.09; 'subject:files': 0.09; 'python': 0.11; '"is': 0.16; '-tkc': 0.16; 'caches': 0.16; 'else"': 0.16; 'erroneously': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'loop.': 0.16; 'maildir': 0.16; 'matters,': 0.16; 'os.walk': 0.16; 'script,': 0.16; 'subject:between': 0.16; 'text",': 0.16; 'directory.': 0.24; 'fine': 0.24; 'subject:/': 0.26; 'possibility': 0.29; 'reporting': 0.29; 'flags': 0.31; 'them?': 0.31; 'file': 0.32; 'knows': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'c++': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'being': 0.38; 'sometimes': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'little': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'tell': 0.60; 'such': 0.63; 'myself': 0.63; 'more': 0.64; 'holding': 0.65; 'walk': 0.74; 'alongside': 0.84; 'directories,': 0.84; 'distinguish': 0.84; 'received:50.22': 0.84 Date: Sun, 31 Aug 2014 13:45:25 -0500 From: Tim Chase To: python-list@python.org Subject: Distinguishing between maildir, mbox, and MH files/directories? X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409510831 news.xs4all.nl 2848 [2001:888:2000:d::a6]:56679 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77354 Tinkering around with a little script, I found myself with the need to walk a directory tree and process mail messaged found within. Sometimes these end up being mbox files (with multiple messages within), sometimes it's a Maildir structure with messages in each individual file and extra holding directories, and sometimes it's a MH directory. To complicate matters, there's also the possibility of non-{mbox,maildir,mh) files such as binary MUA caches appearing alongside these messages. Python knows how to handle each just fine as long as I tell it what type of file to expect. But is there a straight-forward way to distinguish them? (FWIW, the *nix "file" utility is just reporting "ASCII text", sometimes "with very long lines", and sometimes erroneously flags them as C or C++ files=E2=80=BD). All I need is "is it maildir, mbox, mh, or something else" (I don't have to get more complex for the "something else") inside an os.walk loop. Thanks for any suggestions, -tkc