changeset 1154:44632345fbfb

mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 10 Aug 2006 16:03:44 +0200
parents ad1080735ef8
children bb4758056a46
files MoinMoin/mail/mailimport.py MoinMoin/user.py
diffstat 2 files changed, 37 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mail/mailimport.py	Thu Aug 10 14:13:14 2006 +0200
+++ b/MoinMoin/mail/mailimport.py	Thu Aug 10 16:03:44 2006 +0200
@@ -4,7 +4,8 @@
     Just call this script with the URL of the wiki as a single argument
     and feed the mail into stdin.
 
-    @copyright: 2006 by MoinMoin:AlexanderSchremmer
+    @copyright: 2006 by MoinMoin:AlexanderSchremmer,
+                2006 by MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -53,6 +54,18 @@
         chunks_decoded.append(i[0].decode(i[1] or 'ascii'))
     return u''.join(chunks_decoded).strip()
 
+def email_to_markup(request, email):
+    """ transform the (realname, mailaddr) tuple we get in email argument to
+        some string usable as wiki markup, that represents that person (either
+        HomePage link for a wiki user, or just the realname of the person). """
+    realname, mailaddr = email
+    u = user.get_by_email_address(request, mailaddr)
+    if u:
+        markup = u.wikiHomeLink()
+    else:
+        markup = realname or mailaddr
+    return markup
+
 def process_message(message):
     """ Processes the read message and decodes attachments. """
     attachments = []
@@ -158,7 +171,6 @@
 def import_mail_from_file(request, infile):
     """ Reads an RFC 822 compliant message from the file `infile` and imports it to
         the wiki. """
-
     return import_mail_from_message(request, email.message_from_file(infile))
 
 def import_mail_from_message(request, message):
@@ -242,8 +254,9 @@
         table_header = (u"\n\n## mail_overview (don't delete this line)\n" +
                         u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Subject)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Link)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
                        )
-        from_col = msg['from_addr'][0] or msg['from_addr'][1]
-        to_col = msg['to_addr'][0] or msg['to_addr'][1]
+
+        from_col = email_to_markup(request, msg['from_addr'])
+        to_col = email_to_markup(request, msg['to_addr'])
         subj_col = msg['subject']
         date_col = msg['date']
         page_col = pagename
--- a/MoinMoin/user.py	Thu Aug 10 14:13:14 2006 +0200
+++ b/MoinMoin/user.py	Thu Aug 10 16:03:44 2006 +0200
@@ -914,31 +914,35 @@
         host = self.isCurrentUser() and self._cfg.show_hosts and self._request.remote_addr
         return host or _("<unknown>")
 
+    def wikiHomeLink(self):
+        """ return wiki markup usable as a link to the user homepage,
+            it doesn't matter whether it already exists or not.
+        """
+        wikiname, pagename = wikiutil.getInterwikiHomePage(self._request, self.name)
+        if wikiname == 'Self':
+            if wikiutil.isStrictWikiname(self.name):
+                markup = pagename
+            else:
+                markup = '["%s"]' % pagename
+        else:
+            markup = '%s:%s' % (wikiname, pagename) # TODO: support spaces in pagename
+        return markup
+
     def signature(self):
-        """ Return user signature using markup
+        """ Return user signature using wiki markup
         
-        Users sign with a link to their homepage, or with text if they
-        don't have one. The text may be parsed as a link if it's using
-        CamelCase. Visitors return their host address.
+        Users sign with a link to their homepage.
+        Visitors return their host address.
         
         TODO: The signature use wiki format only, for example, it will
         not create a link when using rst format. It will also break if
         we change wiki syntax.
         """
-        if not self.name:
+        if self.name:
+            return self.wikiHomeLink()
+        else:
             return self.host()
 
-        wikiname, pagename = wikiutil.getInterwikiHomePage(self._request,
-                                                           self.name)
-        if wikiname == 'Self':
-            if not wikiutil.isStrictWikiname(self.name):
-                markup = '["%s"]' % pagename
-            else:
-                markup = pagename
-        else:
-            markup = '%s:%s' % (wikiname, pagename)
-        return markup
-
     def mailAccountData(self, cleartext_passwd=None):
         from MoinMoin.mail import sendmail
         from MoinMoin.wikiutil import getSysPage