use of dev.hawala.xns.level4.mailing.MailingCommon.UndeliveredName 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());
}
}
Aggregations