/* FARGOS Development, LLC Sample Programs Copyright (C) 2002 FARGOS Development, LLC. All rights reserved. mailto:support@fargos.net for assistance. NOTE: in the future, enhanced versions of these classes may be added to the FARGOS/VISTA Object Management Environment core within the Standard namespace. Developers can avoid any potential conflict if they specify an explicit namespace when creating instances of the sample classes. */ %include implicit { const string MAILBOX_SERVICE = "MailboxDirectory"; }; class Local . SMTPmailboxService { string databaseName; assoc userNameToMailbox; assoc mailboxAliases; } inherits from PersistentObject; SMTPmailboxService:create(optional string dbName) { if (argc != 0) { databaseName = dbName; } else { databaseName = "mailboxes"; } call "SMTPmailboxService:initialize"(); call "PersistentObject:initialize"(databaseName); } SMTPmailboxService:initialize() { registerService(MAILBOX_SERVICE, thisObject, 0); return (0); } SMTPmailboxService:delete() { unregisterService(MAILBOX_SERVICE, thisObject); } SMTPmailboxService:objectImported() { call "SMTPmailboxService:initialize"(); } SMTPmailboxService:getDatabaseName() { return (databaseName); } SMTPmailboxService:registerMailbox(string mailboxName, oid mailbox) { if (indexExists(userNameToMailbox, mailboxName) != 0) { return (-1); } userNameToMailbox[mailboxName] = mailbox; string 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) { if (indexExists(userNameToMailbox, mailboxName) != 0) { return (userNameToMailbox[mailboxName]); } if (indexExists(mailboxAliases, mailboxName) != 0) { string 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 string databaseName = send "getDatabaseName" to MAILBOX_SERVICE; call "PersistentObject:initialize"(databaseName, 1); return (0); } SMTPmailbox:delete() { send "unregisterMailbox"(userName, thisObject) to MAILBOX_SERVICE from nil; send "unregisterAliases"(fullyQualified, "<" + fullyQualified + ">") to MAILBOX_SERVICE from nil; } SMTPmailbox:objectImported() { logOutput(LOG_INFO, "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 = nextIndex(messages, 0); while (i != 0) { ids[i] = length(messages[i]); i = nextIndex(messages, i); } return (ids); } SMTPmailbox:storeMail(string mailBody) { logOutput(LOG_DEBUG, "Store email message:\n", mailBody, "\n"); 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) { if (indexExists(messages, messageID) == 0) { return ("doesNotExist"); } string hash = SHA1hash(messages[messageID]); string 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 i; if (indexExists(messages, messageID) == 0) { return (nil); } string mess = messages[messageID]; int 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