%include implicit { const string MAILBOX_SERVICE = "MailboxDirectory"; }; class Local . SMTPmailboxService { assoc userNameToMailbox; assoc mailboxAliases; } inherits from Object; SMTPmailboxService:create() { // TO DO: use oid that only permits lookup/register operations registerService(MAILBOX_SERVICE, thisObject, 0); } SMTPmailboxService:delete() { unregisterService(MAILBOX_SERVICE, thisObject); } SMTPmailboxService:registerMailbox(string mailboxName, oid mailbox) { string bracketKey; if (indexExists(userNameToMailbox, mailboxName) != 0) { return (-1); } userNameToMailbox[mailboxName] = mailbox; bracketKey = makeAsString("<", mailboxName, ">"); mailboxAliases[bracketKey] = mailboxName; return (0); } SMTPmailboxService:registerAliases(string mailboxName, string alias1) { int i; for(i=1;i"); userNameToMailbox = deleteIndex(mailboxAliases, bracketKey); return (0); } SMTPmailboxService:lookupMailbox(string mailboxName) { string name; if (indexExists(userNameToMailbox, mailboxName) != 0) { return (userNameToMailbox[mailboxName]); } if (indexExists(mailboxAliases, mailboxName) != 0) { name = mailboxAliases[mailboxName]; if (indexExists(userNameToMailbox, name) != 0) { return (userNameToMailbox[name]); } } return (nil); } SMTPmailboxService:listMailboxes() { array result; int count, i; i = nextIndex(userNameToMailbox, 0); while (i != 0) { result[count] = getKeyForIndex(userNameToMailbox, i); count += 1; i = nextIndex(userNameToMailbox, i); } return (result); } class Local . SMTPmailbox (1) { string userName; string fullName; string fullyQualified; string password; array messages; int messageTotal; } inherits from PersistentObject; SMTPmailbox:create(string forUser, string longName, string pw) { /*! See method=initialize. !*/ if (argc != 0) { call "SMTPmailbox:initialize"(arrayToSet(argv)); } } SMTPmailbox:initialize(string forUser, string longName, string pw) { userName = forUser; if (typeOf(longName) == string) { fullName = longName; } else { fullName = userName; } if (findSubstring(userName, "@") != -1) { fullyQualified = userName; } else { fullyQualified = makeAsString(userName, "@", getSystemInfoAttribute("hostName")); } if (length(pw) > 0) { password = pw; } else { password = "test"; } send "registerMailbox"(userName, thisObject) to MAILBOX_SERVICE from nil; send "registerAliases"(userName, fullyQualified, "<" + fullyQualified + ">") to MAILBOX_SERVICE from nil; // Initialize persistence, associate with "mailboxes" database call "PersistentObject:initialize"("mailboxes"); return (0); } SMTPmailbox:delete() { send "unregisterMailbox"(userName, thisObject) to MAILBOX_SERVICE from nil; send "unregisterAliases"(fullyQualified, "<" + fullyQualified + ">") to MAILBOX_SERVICE from nil; } SMTPmailbox:objectImported() { display("MAILBOX for ", userName, " imported\n"); send "registerMailbox"(userName, thisObject) to MAILBOX_SERVICE from nil; send "registerAliases"(userName, fullyQualified, "<" + fullyQualified + ">") to MAILBOX_SERVICE from nil; } SMTPmailbox:authenticate(string checkPassword) { if (checkPassword == password) return (1); return (0); } SMTPmailbox:changePassword(string newPassword, string checkPassword) { if (checkPassword != password) { return (-1); } password = newPassword; return (0); } SMTPmailbox:getMailboxInfo() { assoc attrs; attrs["userName"] = userName; attrs["fullName"] = fullName; attrs["fqName"] = fullyQualified; return (attrs); } SMTPmailbox:getMessageIds() { array ids; int i; i = nextIndex(messages, 0); while (i != 0) { ids[i] = length(messages[i]); i = nextIndex(messages, i); } return (ids); } SMTPmailbox:storeMail(string mailBody) { debugDisplay(debugLogLevel2, "Store email message:\n", mailBody); messageTotal += 1; messages[messageTotal] = mailBody; return (messageTotal); } SMTPmailbox:getMessage(int messageID) { if (indexExists(messages, messageID) == 0) { return (nil); } return (messages[messageID]); } // Provided for POP3 UIDL command; permit hash to be done locally // rather than transmit entire message body between systems SMTPmailbox:getUniqueMessageId(int messageID) { string hash, text; if (indexExists(messages, messageID) == 0) { return ("doesNotExist"); } hash = SHA1hash(messages[messageID]); text = makeAsHexString(hash); return (text); } // Provided for POP3 TOP command; do work locally rather than transmit // entire message body between systems SMTPmailbox:getMessageHeader(int messageID, int bodyLines) { int offset, nextOffset, i; string mess, head; if (indexExists(messages, messageID) == 0) { return (nil); } mess = messages[messageID]; offset = findSubstring(mess, "\r\n\r\n"); // end of MIME header if (offset == -1) { // no end of MIME header, return everything return (mess); } offset += 4; // length of CR LF CR LF for(i=0;i