[pan2] https://bugzilla.gnome.org/show_bug.cgi?id=550007



commit 6be39063508ee21a93d18725a8de775031695513
Author: Heinrich MÃlller <henmull src gnome org>
Date:   Sun May 6 14:31:57 2012 +0200

    https://bugzilla.gnome.org/show_bug.cgi?id=550007

 pan/data/article.cc               |    5 --
 pan/gui/body-pane.cc              |   20 -------
 pan/gui/save-attach-ui.cc         |   40 ++-------------
 pan/gui/save-ui.cc                |   35 +------------
 pan/tasks/task-article.cc         |    3 +-
 pan/usenet-utils/text-massager.cc |  101 +++++++++++++++++++++++++++++++++++++
 pan/usenet-utils/text-massager.h  |    8 +++
 7 files changed, 119 insertions(+), 93 deletions(-)
---
diff --git a/pan/data/article.cc b/pan/data/article.cc
index 9bdb92a..fa07591 100644
--- a/pan/data/article.cc
+++ b/pan/data/article.cc
@@ -26,11 +26,6 @@
 #include <pan/general/string-view.h>
 #include "article.h"
 
-#ifdef HAVE_ODB
-  #include <odb/database.hxx>
-  #include <odb/transaction.hxx>
-#endif
-
 using namespace pan;
 
 Article :: PartState
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 441d19a..b158bbf 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -1219,26 +1219,6 @@ BodyPane :: refresh ()
   set_text_from_message (_message);
 }
 
-namespace
-{
-
-  /** Separates user id into name and email address */
-  std::pair<std::string,std::string> get_email_address(std::string& s)
-  {
-    std::pair<std::string,std::string> ret;
-    size_t in = s.find("<");
-    size_t out = s.find(">");
-    if (in == std::string::npos ||
-        out == std::string::npos)
-      return ret;
-
-    ret.first = s.substr(0,in-1);
-    ret.second = s.substr (in+1,out-in-1);
-
-    return ret;
-  }
-}
-
 #ifdef HAVE_GMIME_CRYPTO
 gboolean
 BodyPane :: on_verbose_tooltip_cb(GtkWidget  *widget,
diff --git a/pan/gui/save-attach-ui.cc b/pan/gui/save-attach-ui.cc
index 1c389cf..bddff65 100644
--- a/pan/gui/save-attach-ui.cc
+++ b/pan/gui/save-attach-ui.cc
@@ -38,47 +38,17 @@ using namespace pan;
 
 namespace
 {
-  std::string expand_download_dir (const char * dir, const StringView& group)
-  {
-    std::string val (dir);
-    std::string::size_type pos;
-
-    while (((pos = val.find ("%g"))) != val.npos)
-      val.replace (pos, 2, group.str, group.len);
-
-    std::string tmp (group.str, group.len);
-    std::replace (tmp.begin(), tmp.end(), '.', G_DIR_SEPARATOR);
-    while (((pos = val.find ("%G"))) != val.npos)
-      val.replace (pos, 2, tmp);
-
-    return val;
-  }
-
-  std::string expand_download_dir_subject (const char * dir, const char * subjectline, const std::string &sep)
-  {
-    std::string val (dir);
-    std::string sub (subject_to_path(subjectline, false, sep));
-    std::string::size_type pos;
-
-    while (((pos = val.find ("%s"))) != val.npos)
-      val.replace (pos, 2, sub);
-
-    sub = subject_to_path(subjectline, true, sep);
-    while (((pos = val.find ("%S"))) != val.npos)
-      val.replace (pos, 2, sub);
-
-    return val;
-  }
-
 
   void
   show_group_substitution_help_dialog (gpointer window)
   {
     const char * str = _("%g - group as one directory (alt.binaries.pictures.trains)\n"
                          "%G - group as nested directory (/alt/binaries/pictures/trains)\n"
-                         "%s - subject line excerpt\n"
-                         "%S - subject line\n"
-                         " \n"
+                         "%s - Subject line excerpt\n"
+                         "%S - Subject line\n"
+                         "%n - Poster display name\n"
+                         "%e - Poster e-mail adress\n"
+                         "%d - Current Date\n"
                          "\"/home/user/News/Pan/%g\" becomes\n"
                          "\"/home/user/News/Pan/alt.binaries.pictures.trains\", and\n"
                          "\"/home/user/News/Pan/%G\" becomes\n"
diff --git a/pan/gui/save-ui.cc b/pan/gui/save-ui.cc
index e19ce39..c620225 100644
--- a/pan/gui/save-ui.cc
+++ b/pan/gui/save-ui.cc
@@ -38,38 +38,6 @@ using namespace pan;
 
 namespace
 {
-  std::string expand_download_dir (const char * dir, const StringView& group)
-  {
-    std::string val (dir);
-    std::string::size_type pos;
-
-    while (((pos = val.find ("%g"))) != val.npos)
-      val.replace (pos, 2, group.str, group.len);
-
-    std::string tmp (group.str, group.len);
-    std::replace (tmp.begin(), tmp.end(), '.', G_DIR_SEPARATOR);
-    while (((pos = val.find ("%G"))) != val.npos)
-      val.replace (pos, 2, tmp);
-
-    return val;
-  }
-
-  std::string expand_download_dir_subject (const char * dir, const char * subjectline, const std::string &sep)
-  {
-    std::string val (dir);
-    std::string sub (subject_to_path(subjectline, false, sep));
-    std::string::size_type pos;
-
-    while (((pos = val.find ("%s"))) != val.npos)
-      val.replace (pos, 2, sub);
-
-    sub = subject_to_path(subjectline, true, sep);
-    while (((pos = val.find ("%S"))) != val.npos)
-      val.replace (pos, 2, sub);
-
-    return val;
-  }
-
 
   void
   show_group_substitution_help_dialog (gpointer window)
@@ -78,6 +46,9 @@ namespace
                          "%G - group as nested directory (/alt/binaries/pictures/trains)\n"
                          "%s - subject line excerpt\n"
                          "%S - subject line\n"
+                         "%n - Poster display name\n"
+                         "%e - Poster e-mail adress\n"
+                         "%d - Current Date\n"
                          " \n"
                          "\"/home/user/News/Pan/%g\" becomes\n"
                          "\"/home/user/News/Pan/alt.binaries.pictures.trains\", and\n"
diff --git a/pan/tasks/task-article.cc b/pan/tasks/task-article.cc
index 50f0f55..3f718bd 100644
--- a/pan/tasks/task-article.cc
+++ b/pan/tasks/task-article.cc
@@ -34,6 +34,7 @@ extern "C"
 #include <pan/general/log.h>
 #include <pan/general/macros.h>
 #include <pan/usenet-utils/mime-utils.h>
+#include <pan/usenet-utils/text-massager.h>
 #include <pan/data/article-cache.h>
 #include "decoder.h"
 #include "task-article.h"
@@ -93,7 +94,7 @@ TaskArticle :: TaskArticle (const ServerRank          & server_rank,
                             const char                * filename,
                             const SaveOptions         & options):
   Task (save_path.empty() ? "BODIES" : "SAVE", get_description (article, !save_path.empty())),
-  _save_path (save_path),
+  _save_path (expand_attachment_headers(save_path, article)),
   _server_rank (server_rank),
   _cache (cache),
   _read (read),
diff --git a/pan/usenet-utils/text-massager.cc b/pan/usenet-utils/text-massager.cc
index 6e9c611..f4b04cc 100644
--- a/pan/usenet-utils/text-massager.cc
+++ b/pan/usenet-utils/text-massager.cc
@@ -27,6 +27,8 @@ extern "C" {
 }
 #include "text-massager.h"
 #include <pan/general/log.h>
+#include <pan/general/e-util.h>
+
 using namespace pan;
 
 TextMassager :: TextMassager ():
@@ -520,3 +522,102 @@ pan :: subject_to_path (const char * subjectline, bool full_subj, const std::str
   //std::cout << "\nSubject was: '" << subjectline << "'\nSubject now: '" << val << "'" << std::endl;
   return val;
 }
+
+std::string
+pan :: expand_download_dir (const char * dir, const StringView& group)
+{
+  std::string val (dir);
+  std::string::size_type pos;
+
+  while (((pos = val.find ("%g"))) != val.npos)
+    val.replace (pos, 2, group.str, group.len);
+
+  std::string tmp (group.str, group.len);
+  std::replace (tmp.begin(), tmp.end(), '.', G_DIR_SEPARATOR);
+  while (((pos = val.find ("%G"))) != val.npos)
+    val.replace (pos, 2, tmp);
+
+  return val;
+}
+
+std::string
+pan :: expand_download_dir_subject (const char * dir, const char * subjectline, const std::string &sep)
+{
+  std::string val (dir);
+  std::string sub (subject_to_path(subjectline, false, sep));
+  std::string::size_type pos;
+
+  while (((pos = val.find ("%s"))) != val.npos)
+    val.replace (pos, 2, sub);
+
+  sub = subject_to_path(subjectline, true, sep);
+  while (((pos = val.find ("%S"))) != val.npos)
+    val.replace (pos, 2, sub);
+
+  return val;
+}
+
+/*
+"%n - Poster display name\n"
+"%e - Poster e-mail adress\n"
+"%d - Current Date\n"
+*/
+std::string
+pan :: expand_attachment_headers(const Quark& path, const Article& article)
+{
+  std::string val(path.c_str());
+  std::string::size_type pos;
+  std::string author_str (article.author.c_str());
+  std::pair<std::string,std::string> author (get_email_address(author_str));
+  std::string author_name (author.first);
+  std::string author_email (author.second);
+
+  EvolutionDateMaker ed;
+  std::string now (ed.get_date_string (article.time_posted));
+
+  if (author_name.empty())  author_name  = _("no_name");
+  if (author_email.empty()) author_email = _("no_mail");
+
+  while (((pos = val.find ("%n"))) != val.npos)
+    val.replace (pos, 2, author_name);
+
+  while (((pos = val.find ("%e"))) != val.npos)
+    val.replace (pos, 2, author_email);
+
+  while (((pos = val.find ("%d"))) != val.npos)
+    val.replace (pos, 2, now);
+
+  return val;
+}
+
+/** Separates user id into name and email address */
+std::pair<std::string,std::string> pan :: get_email_address(std::string& s)
+{
+  std::pair<std::string,std::string> ret;
+  size_t in  (s.find("<"));
+  size_t out (s.find(">"));
+  if (in == s.npos && out == s.npos)
+  {
+    if (s.find("@") != s.npos)
+    {
+      size_t bracket_in (s.find("("));
+      size_t bracket_out (s.find(")"));
+      if (bracket_in != s.npos && bracket_out != s.npos)
+      {
+        ret.first = s.substr(0, bracket_in-1);
+        ret.second = s.substr(bracket_in+1, bracket_out-bracket_in-1);
+      }
+    }
+  }
+  else if (in == s.npos || out == s.npos)
+  {
+    return ret;
+  }
+  else
+  {
+    ret.first = s.substr(0,in-1);
+    ret.second = s.substr (in+1,out-in-1);
+  }
+
+  return ret;
+}
diff --git a/pan/usenet-utils/text-massager.h b/pan/usenet-utils/text-massager.h
index e89f9e6..5c431bd 100644
--- a/pan/usenet-utils/text-massager.h
+++ b/pan/usenet-utils/text-massager.h
@@ -24,6 +24,8 @@
 #include <climits>
 #include <set>
 #include <pan/general/string-view.h>
+#include <pan/general/quark.h>
+#include <pan/data/article.h>
 
 namespace pan
 {
@@ -62,6 +64,12 @@ namespace pan
    */
    std::string subject_to_path (const char * subjectline, bool full_subj, const std::string &seperator);
 
+   std::string expand_download_dir_subject (const char * dir, const char * subjectline, const std::string &sep);
+   std::string expand_download_dir (const char * dir, const StringView& group);
+   std::string expand_attachment_headers(const Quark& path, const Article& article);
+
+   std::pair<std::string,std::string> get_email_address(std::string& s);
+
 }
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]