sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 9ab7e4ff24d6c718415fecae8ad58acbc62e223e
parent f1a13dd2a9b9b8259d29d0ed7523b21a5fd1fff8
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Sat, 27 Oct 2007 19:06:21 +0000

prohibit aliases from containing spaces

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@622 5c8cc53c-5e98-4d25-b20a-d8db53a31250

Diffstat:
M lib/sup/contact.rb | 9 +++++++++
M lib/sup/modes/contact-list-mode.rb | 6 +++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
@@ -1,5 +1,7 @@
 module Redwood
 
+class InvalidAliasError < StandardError; end
+
 class ContactManager
   include Singleton
 
@@ -23,6 +25,8 @@ class ContactManager
 
   def contacts; @p2a.keys; end
   def set_contact person, aalias
+    raise InvalidAliasError unless valid_alias? aalias
+
     if(pold = @a2p[aalias]) && (pold != person)
       drop_contact pold
     end
@@ -38,6 +42,11 @@ class ContactManager
   def contact_for aalias; @a2p[aalias]; end
   def alias_for person; @p2a[person]; end
   def is_contact? person; @p2a.member? person; end
+
+  def valid_alias? a
+    a =~ /^\S+$/
+  end
+
   def save
     File.open(@fn, "w") do |f|
       @p2a.each do |p, a|
diff --git a/lib/sup/modes/contact-list-mode.rb b/lib/sup/modes/contact-list-mode.rb
@@ -6,7 +6,11 @@ module CanAliasContacts
     if a.empty?
       ContactManager.drop_contact p
     else
-      ContactManager.set_contact p, a
+      begin
+        ContactManager.set_contact p, a
+      rescue InvalidAliasError
+        BufferManager.flash "Error: nickname cannot contain spaces."
+      end
     end
   end
 end