Commits

Anonymous committed 1d2fdca

Made articles from email settings less work. Updated README

Comments (0)

Files changed (2)

+.. -*- restructuredtext -*-
+
 django-articles is the blog engine that I use on codekoala.com
 
 Features
 * Auto-completion for tags in the Django admin
 * Ability to post in the future
 * Article expiration facilities
-* Allows articles to be written in plain text/HTML or using Markdown, ReStructured Text, or Textile markup
+* Articles from email
+* Allows articles to be written in plain text/HTML or using Markdown,
+  ReStructured Text, or Textile markup
 * Related articles
 * Follow-up articles
 * Disqus comments
 Requirements
 ============
 
-``django-articles`` wants a modern version of Django--something after 1.1.  It used to rely on ``django.contrib.comments`` for commenting needs, but I recently switched to `Disqus <http://www.disqus.com/>`_.  Included herein is a management command to convert ``django.contrib.comments`` comments to Disqus.
+``django-articles`` wants a modern version of Django--something after 1.1.  It
+used to rely on ``django.contrib.comments`` for commenting needs, but I
+recently switched to `Disqus <http://www.disqus.com/>`_.  Included herein is a
+management command to convert ``django.contrib.comments`` comments to Disqus.
 
-This project also expects ``django.contrib.sites``, ``django.contrib.admin``, ``django.contrib.markup``, ``django.contrib.auth``, ``django.contrib.humanize``, and ``django.contrib.syndication`` to be properly installed.
+This project also expects ``django.contrib.sites``, ``django.contrib.admin``,
+``django.contrib.markup``, ``django.contrib.auth``,
+``django.contrib.humanize``, and ``django.contrib.syndication`` to be properly
+installed.
 
 Installation
 ============
 Configuration
 =============
 
-First of all, you must add this project to your list of ``INSTALLED_APPS`` in ``settings.py``::
+First of all, you must add this project to your list of ``INSTALLED_APPS`` in
+``settings.py``::
 
     INSTALLED_APPS = (
         'django.contrib.admin',
         'django.contrib.sessions',
         'django.contrib.sites',
         'django.contrib.syndication',
-        ...
+        ... 
         'articles',
         ...
     )
 
-Run ``manage.py syncdb``.  This creates a few tables in your database that are necessary for operation.
+Run ``manage.py syncdb``.  This creates a few tables in your database that are
+necessary for operation.
 
 Next, set a couple of settings in your ``settings.py``:
 
- * ``DISQUS_USER_API_KEY``: Your user API key from Disqus.  This is free, and you can learn how to get it from  `Disqus's API Page <http://2ze.us/ME>`_ or you can try http://disqus.com/api/get_my_key/ when you're logged into Disqus.  You only need this one if you're going to be converting comments from ``django.contrib.comments`` to Disqus.
- * ``DISQUS_FORUM_SHORTNAME``: set this to ``True`` if you want to see markers on the map
+* ``DISQUS_USER_API_KEY``: Your user API key from Disqus.  This is free, and
+  you can learn how to get it from  `Disqus's API Page <http://2ze.us/ME>`_ or
+  you can try http://disqus.com/api/get_my_key/ when you're logged into Disqus.
+  You only need this one if you're going to be converting comments from
+  ``django.contrib.comments`` to Disqus.
+* ``DISQUS_FORUM_SHORTNAME``: set this to ``True`` if you want to see markers
+  on the map
 
 Template Integration
 ====================
 
-There are several template blocks that ``django-articles`` expects your ``base.html`` file to contain:
+There are several template blocks that ``django-articles`` expects your
+``base.html`` file to contain:
 
 * ``title``
 * ``meta-keywords``
 Tag Auto-Completion
 ===================
 
-If you would like to take advantage of the auto-completion feature for tags, copy the files from the ``articles/media`` directories into your static media directory.  ``django-articles`` expects to find each of those directories/files in your ``settings.MEDIA_URL`` directory--if this does not suit your needs, you may override the ``Media`` class of ``articles.forms.ArticleAdminForm`` with the appropriate paths.
+If you would like to take advantage of the auto-completion feature for tags,
+copy the files from the ``articles/media`` directories into your static media
+directory.  ``django-articles`` expects to find each of those directories/files
+in your ``settings.MEDIA_URL`` directory--if this does not suit your needs, you
+may override the ``Media`` class of ``articles.forms.ArticleAdminForm`` with
+the appropriate paths.
 
-Another assumption that is made by this feature is that the prefix you assign to your ``django-articles`` installation in your ``ROOT_URLCONF`` will be ``^blog/``.  For example::
+Another assumption that is made by this feature is that the prefix you assign
+to your ``django-articles`` installation in your ``ROOT_URLCONF`` will be
+``^blog/``.  For example::
 
     url(r'^blog', include('articles.urls')),
 
-If this does not match your installation, all you need to change is the ``js/tag_autocomplete.js`` to reflect the proper path.
+If this does not match your installation, all you need to change is the
+``js/tag_autocomplete.js`` to reflect the proper path.
 
 When that's done, you should be able to begin using ``django-articles``!
 
 .. versionadded:: 0.9.1
    Articles from email
 
-I've been working on making it possible for ``django-articles`` to post articles that you email to a special mailbox.  This seems to be working on the most basic levels right now.  It's not been tested in very many scenarios, and I would appreciate it if you could post problems with it in the ticket tracker at http://bitbucket.org/codekoala/django-articles/ so we can make it work really well.
+I've been working on making it possible for ``django-articles`` to post
+articles that you email to a special mailbox.  This seems to be working on the
+most basic levels right now.  It's not been tested in very many scenarios, and
+I would appreciate it if you could post problems with it in the ticket tracker
+at http://bitbucket.org/codekoala/django-articles/ so we can make it work
+really well.
 
 Things to keep in mind:
 
-* Any **active** user who is a ``django.contrib.auth.models.User`` and has an email address associated with their user information is a valid sender for articles from email.  This is how the author of an article is determined.
-* Only the following fields are currently populated by the articles from email feature:
+* Any **active** user who is a ``django.contrib.auth.models.User`` and has an
+email address associated with their user information is a valid sender for
+articles from email.  This is how the author of an article is determined.  *
+Only the following fields are currently populated by the articles from email
+feature:
 
     * author
     * title
     * publish_date
     * is_active
 
-  Any and all other attributes about an article must be configured later on using the standard mechanisms (aka the Django admin).
-* There is a new management command to handle all of the magic for this feature: ``check_for_articles_from_email``.  This command is intended to be called either manually or via external scheduling utilities (like ``cron``)
-* Email messages **are deleted** after they are turned into articles.  This means that you should probably have a *special mailbox dedicated to django-article and articles from email*.  However, only emails whose sender matches the email address of an active user are deleted (as described above).
-* Attachments are currently not bothered with.  Don't worry, they will be :D
+  Any and all other attributes about an article must be configured later on
+  using the standard mechanisms (aka the Django admin).
+* There is a new management command to handle all of the magic for this
+  feature: ``check_for_articles_from_email``.  This command is intended to be
+  called either manually or via external scheduling utilities (like ``cron``)
+* Email messages **are deleted** after they are turned into articles.  This
+  means that you should probably have a *special mailbox dedicated to
+  django-articles and articles from email*.  However, only emails whose sender
+  matches the email address of an active user are deleted (as described above).
+* Attachments are currently not bothered with.  Don't worry, they will be in
+  the future. :D
 
 Configuration
 -------------
 
-There are several new variables that you can configure in your ``settings.py`` to enable articles from email:
+There are several new variables that you can configure in your ``settings.py``
+to enable articles from email, specifying a ``ARTICLES_FROM_EMAIL`` dictionary:
 
-* ``ARTICLES_EMAIL_PROTOCOL`` - Either ``IMAP4`` or ``POP3``.  *Default*: ``IMAP4``
-* ``ARTICLES_EMAIL_HOST`` - The mail server. *Example*: mail.yourserver.com
-* ``ARTICLES_EMAIL_PORT`` - The port to use to connect to your mail server
-* ``ARTICLES_EMAIL_KEYFILE`` - The keyfile used to access your mail server *untested*
-* ``ARTICLES_EMAIL_CERTFILE`` - The certfile used to access your mail server *untested*
-* ``ARTICLES_EMAIL_USER`` - The username used to access your mailbox
-* ``ARTICLES_EMAIL_PASSWORD`` - The password associated with the user to access your mailbox
-* ``ARTICLES_EMAIL_SSL`` - Whether or not to connect to the mail server using SSL.  *Default*: ``False``
-* ``ARTICLES_EMAIL_AUTOPOST`` - Whether or not to automatically post articles that are created from email messages.  If this is ``False``, the articles will be marked as inactive and you must manually make them active. *Default*: ``False``
-* ``ARTICLES_EMAIL_MARKUP`` - The default markup language to use for articles from email.  Options include:
+* ``protocol`` - Either ``IMAP4`` or ``POP3``.  *Default*: ``IMAP4``
+* ``host`` - The mail server. *Example*: ``mail.yourserver.com``
+* ``port`` - The port to use to connect to your mail server
+* ``keyfile`` - The keyfile used to access your mail server.  This is only used
+  if ``ssl`` is ``True``, and even then it's optional. *untested*
+* ``certfile`` - The certfile used to access your mail server.  This is only
+  used if ``ssl`` is ``True``, and even then it's optional. *untested*
+* ``user`` - The username used to access your mailbox
+* ``password`` - The password associated with the user to access your mailbox
+* ``ssl`` - Whether or not to connect to the mail server using SSL.  *Default*:
+  ``False``
+* ``autopost`` - Whether or not to automatically post articles that are created
+  from email messages.  If this is ``False``, the articles will be marked as
+  inactive and you must manually make them active. *Default*: ``False``
+* ``markup`` - The default markup language to use for articles from email.
+  Options include:
 
     * ``h`` for HTML/plain text
     * ``m`` for Markdown
     * ``t`` for Textile
 
   *Default*: ``h``
+* ``acknowledge`` - Whether or not to email out an acknowledgment
+  message when articles are created from email.  *Default*: ``False``
 
-* ``ARTICLES_EMAIL_ACK`` - Whether or not to email out an acknowledgment message when articles are created from email.  *Default*: ``False``
+Example configuration::
 
-Good luck!  Please contact me with any questions or concerns you have with the project!
+    ARTICLES_FROM_EMAIL = {
+        'protocol': 'IMAP4',
+        'host': 'mail.yourserver.com',
+        'port': 9000,
+        'keyfile': '/path/to/keyfile',
+        'certfile': '/path/to/certfile',
+        'user': 'your_username',
+        'password': 'your_password',
+        'ssl': True,
+        'autopost': True,
+        'markup': 'r',
+        'acknowledge': True,
+    }
 
+Good luck!  Please contact me with any questions or concerns you have with the
+project!
+

articles/management/commands/check_for_articles_from_email.py

     def handle(self, *args, **options):
         """Main entry point for the command"""
 
-        s = lambda k, d: getattr(settings, k, d)
+        # retrieve configuration options--give precedence to CLI parameters
+        self.from_email = getattr(settings, 'ARTICLES_FROM_EMAIL', {})
+        s = lambda k, d: self.from_email.get(k, d)
 
-        # retrieve configuration options--give precedence to CLI parameters
-        protocol = options['protocol'] or s('ARTICLES_EMAIL_PROTOCOL', MB_IMAP4)
-        host = options['host'] or s('ARTICLES_EMAIL_HOST', 'mail.yourhost.com')
-        port = options['port'] or s('ARTICLES_EMAIL_PORT', None)
-        keyfile = options['keyfile'] or s('ARTICLES_EMAIL_KEYFILE', None)
-        certfile = options['certfile'] or s('ARTICLES_EMAIL_CERTFILE', None)
-        username = options['username'] or s('ARTICLES_EMAIL_USER', None)
-        password = options['password'] or s('ARTICLES_EMAIL_PASSWORD', None)
-        ssl = options['ssl'] or s('ARTICLES_EMAIL_SSL', False)
+        protocol = options['protocol'] or s('protocol', MB_IMAP4)
+        host = options['host'] or s('host', 'mail.yourhost.com')
+        port = options['port'] or s('port', None)
+        keyfile = options['keyfile'] or s('keyfile', None)
+        certfile = options['certfile'] or s('certfile', None)
+        username = options['username'] or s('user', None)
+        password = options['password'] or s('password', None)
+        ssl = options['ssl'] or s('ssl', False)
 
         self.verbosity = int(options.get('verbosity', 1))
 
         site = Site.objects.get_current()
 
         # make sure we have a valid default markup
-        ack = getattr(settings, 'ARTICLES_EMAIL_ACK', False)
-        markup = getattr(settings, 'ARTICLES_EMAIL_MARKUP', MARKUP_HTML)
+        ack = self.from_email.get('acknowledge', False)
+        autopost = self.from_email.get('autopost', False)
+        markup = self.from_email.get('markup', MARKUP_HTML)
         if markup not in (MARKUP_HTML, MARKUP_MARKDOWN, MARKUP_REST, MARKUP_TEXTILE):
             markup = MARKUP_HTML
 
             slug = self.get_unique_slug(slugify(title))
 
             content = self.get_email_content(email)
-            autopost = getattr(settings, 'ARTICLES_EMAIL_AUTOPOST', False)
-
             try:
                 # try to grab the timestamp from the email message
                 publish_date = datetime.fromtimestamp(time.mktime(parsedate(email['Date'])))