#
# $Id: group.icn,v 1.2 2004-02-12 17:07:55 rparlett Exp $
#

package mail

import util

#
# This class represents a group, which is a phrase, plus
# zero or more mailboxes.
#
class Group : Address : Error(mailboxes, phrase)
   method get_phrase()
      return phrase
   end

   method set_phrase(x)
      phrase := x
   end

   method get_mailboxes()
      return mailboxes
   end

   method set_mailboxes(x)
      mailboxes := x
   end

   method add_mailbox(x)
     ::put(mailboxes, x)
   end

   method to_rfc822()
      local tmp

      tmp := ""
      every tmp ||:= (!mailboxes).to_rfc822() || ", "
      tmp[-2:0] := ""

      if *phrase > 0 then
         return phrase || ": " || tmp || " ;"
      else
         return ": " || tmp || " ;"
   end

   method parse(s)
      local p
      p := mail::RFC822Parser()
      return p.parse_group(s, self) | error(p)
   end

   method generate_mailboxes()
      suspend !mailboxes
   end

   initially(a[])
      if (*a = 1) & (type(a[1]) == "string") then
         parse(a[1]) | fail
      else {
         mailboxes := a[1] | []
         phrase := a[2] | ""
      }
end

