Search in sources :

Example 1 with InvalidRecipientsErrorRecord

use of dev.hawala.xns.level4.mailing.MailTransport4.InvalidRecipientsErrorRecord in project dodo by devhawala.

the class MailingOldImpl method transport_post.

/*
	 *  post
	 *   = procedure 1
	 */
private static void transport_post(PostParams params, PostResults results) {
    // log ingoing data
    if (logParamsAndResults) {
        StringBuilder sb = new StringBuilder();
        params.append(sb, "  ", "params");
        log("##\n## procedure MailingImpl.transport_post() -- params\n%s\n##\n", sb.toString());
    }
    // check the credentials:
    // - this procedure is called for the generic mail server ("Mail Service:CHServers:CHServers")
    // - not for this specific mail service (which the 1st mail service name in the clearinghouse database)
    // - so use the generic name
    // - and: only the machine id for *this* mail service works...
    Credentials credentials = params.authPair.credentials;
    Verifier verifier = params.authPair.verifier;
    StrongVerifier decodedVerifier = StrongVerifier.make();
    int[] decodedConversationKey = new int[4];
    ThreePartName senderName = // throws an exception on invalid credentials
    mailService.checkCredentials(mailService.getChsDatabase().getGenericMailServiceName(), mailService.getMachineId(), credentials, verifier, decodedConversationKey, decodedVerifier);
    // check the recipients
    NameList allRecipients = NameList.make();
    ChsDatabase chs = mailService.getChsDatabase();
    for (int i = 0; i < params.recipients.size(); i++) {
        Name rcpt = params.recipients.get(i);
        String rcptFqn = chs.resolveName(rcpt);
        List<Name> dlMemberNames;
        if (rcptFqn != null && mailService.hasMailbox(rcptFqn)) {
            Name rcptName = Name.make();
            rcptName.from(rcptFqn);
            allRecipients.addDistinct(rcptName);
        } else if (params.allowDLRecipients.get() && rcptFqn != null && (dlMemberNames = getUserGroupMembersLcFqns(rcptFqn)) != null) {
            for (Name dlMember : dlMemberNames) {
                allRecipients.addDistinct(dlMember);
            }
        } else {
            UndeliveredName undelivered = UndeliveredName.make();
            undelivered.reason.set(UndeliveredNameType.noSuchRecipient);
            undelivered.name.from(rcpt);
            results.invalidNames.add(undelivered);
        }
    }
    // if invalid recipients are not allowed and we have some or if all recipients are invalid: throw error...
    if ((results.invalidNames.size() > 0 && !params.postIfInvalidNames.get()) || results.invalidNames.size() == params.recipients.size()) {
        InvalidRecipientsErrorRecord err = new InvalidRecipientsErrorRecord();
        for (int i = 0; i < results.invalidNames.size(); i++) {
            err.nameList.add(results.invalidNames.get(i));
        }
        err.raise();
    }
    // so create the mail
    try {
        ByteContentSource source = new ByteContentSource(params.content);
        if (allRecipients.size() > 0) {
            int[] mailId = mailService.postMail(senderName, allRecipients, params.contentsType.get(), source);
            for (int i = 0; i < mailId.length; i++) {
                results.msgID.get(i).set(mailId[i]);
            }
        } else {
            // abort bulk-data transfer
            source.read(null);
        }
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    }
    // log outgoing data
    if (logParamsAndResults) {
        StringBuilder sb = new StringBuilder();
        results.append(sb, "  ", "results");
        log("##\n## procedure MailingImpl.transport_post() -- results\n%s\n##\n", sb.toString());
    }
}
Also used : NameList(dev.hawala.xns.level4.mailing.MailingCommon.NameList) InvalidRecipientsErrorRecord(dev.hawala.xns.level4.mailing.MailTransport4.InvalidRecipientsErrorRecord) StrongVerifier(dev.hawala.xns.level4.common.AuthChsCommon.StrongVerifier) Verifier(dev.hawala.xns.level4.common.AuthChsCommon.Verifier) ConnectionErrorRecord(dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord) Name(dev.hawala.xns.level4.common.AuthChsCommon.Name) UndeliveredName(dev.hawala.xns.level4.mailing.MailingCommon.UndeliveredName) ThreePartName(dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName) StrongVerifier(dev.hawala.xns.level4.common.AuthChsCommon.StrongVerifier) ThreePartName(dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName) UndeliveredName(dev.hawala.xns.level4.mailing.MailingCommon.UndeliveredName) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) ChsDatabase(dev.hawala.xns.level4.common.ChsDatabase) ByteContentSource(dev.hawala.xns.level4.filing.ByteContentSource) Credentials(dev.hawala.xns.level4.common.AuthChsCommon.Credentials)

Aggregations

EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)1 Credentials (dev.hawala.xns.level4.common.AuthChsCommon.Credentials)1 Name (dev.hawala.xns.level4.common.AuthChsCommon.Name)1 StrongVerifier (dev.hawala.xns.level4.common.AuthChsCommon.StrongVerifier)1 ThreePartName (dev.hawala.xns.level4.common.AuthChsCommon.ThreePartName)1 Verifier (dev.hawala.xns.level4.common.AuthChsCommon.Verifier)1 ChsDatabase (dev.hawala.xns.level4.common.ChsDatabase)1 ByteContentSource (dev.hawala.xns.level4.filing.ByteContentSource)1 InvalidRecipientsErrorRecord (dev.hawala.xns.level4.mailing.MailTransport4.InvalidRecipientsErrorRecord)1 ConnectionErrorRecord (dev.hawala.xns.level4.mailing.MailingCommon.ConnectionErrorRecord)1 NameList (dev.hawala.xns.level4.mailing.MailingCommon.NameList)1 UndeliveredName (dev.hawala.xns.level4.mailing.MailingCommon.UndeliveredName)1