# # file:: cmd_mail.rb require 'olc/maileditor' # This source code copyright (C) 2009 Craig Smith # All rights reserved. # # Released under the terms of the TeensyMUD Public License # See LICENSE file for additional information. # module Cmd bindtextdomain("cmd") # Mail management command def cmd_mail(args) case args when "", nil if mailbox.size > 0 msg = "" mailbox.each do |mailid| mail = get_object(mailid) read = "" read = "*" if not mail.read msg << "#{mail.id}) #{read}#{mail.subject}\n" end add_event(id, id, :show, msg) else sendto _("You have no messages.") end when /^read (\d+)/ msgid = $1.to_i if mailbox.include? msgid mail = get_object(msgid) mail.read = true msg = _("From: %{name}\n" % {:name => get_object(mail.from).name }) msg << _("Date: %{date}\n" % {:date => mail.date }) msg << _("Subject: %{subject}\n" % {:subject => mail.subject }) msg << mail.body add_event(id, id, :show, msg) else sendto _("Unknown message id.") end when /^del (\d+)/ msgid = $1.to_i if mailbox.include? msgid mail = get_object(msgid) mail.reset mail.unused = true mailbox.delete(msgid) sendto _("Message deleted.") else sendto _("Unknown message id.") end when /^del all/ mailbox.each do |msgid| mail = get_object(msgid) mail.reset mail.unused = true end mailbox.clear sendto _("Mailbox cleared.") when /(\S+)\s*(.*)/ touser = $1 msgsubj = $2 toperson = nil world.all_characters.each do |oid| p = get_object(oid) toperson = p if p.name=~/^#{touser}$/i end if toperson if msgsubj.size > 0 subj = msgsubj else subj = _("No Subject") end emptyletter = nil world.find_objects("mail").each do |m| if m.is_a? MailMsg emptyletter = m if m.unused end end if emptyletter mail = emptyletter mail.reset else mail = MailMsg.new("mail from #{name}", id) end mail.subject = subj mail.from = id mail.to = toperson.id mail.date = Time.now put_object(mail) @mode = :olc @olc = MailEditor.new(id, mail, "body") else sendto _("Unknown user.") end end end end