Skip to content

Commit

Permalink
applying PR apache#4827 Co-authored-by: @sramazzina
Browse files Browse the repository at this point in the history
  • Loading branch information
bamaer committed Feb 12, 2025
1 parent c421d1f commit b2c6178
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class MailServerConnection extends HopMetadataBase implements IHopMetadat

@HopMetadataProperty private String username;

@HopMetadataProperty private String password;
@HopMetadataProperty(password = true)
private String password;

@HopMetadataProperty private boolean useXOAuth2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class MailServerConnectionEditor extends MetadataEditor<MailServerConnect

private Button wCheckServerIdentity;

private Label wlCheckServerIdentity;

private LabelTextVar wTrustedHosts;

public MailServerConnectionEditor(
Expand Down Expand Up @@ -256,9 +254,9 @@ public void createControl(Composite composite) {
lastControl = wSecureConnectionType;

// Use check server identity
wlCheckServerIdentity = new Label(composite, SWT.RIGHT);
Label wlCheckServerIdentity = new Label(composite, SWT.RIGHT);
wlCheckServerIdentity.setText(
BaseMessages.getString(PKG, "ActionMail.CheckServerIdentity.Label"));
BaseMessages.getString(PKG, "MailServerConnectionDialog.CheckServerIdentity"));
PropsUi.setLook(wlCheckServerIdentity);
FormData fdlCheckServerIdentity = new FormData();
fdlCheckServerIdentity.left = new FormAttachment(0, 0);
Expand All @@ -279,20 +277,21 @@ public void widgetSelected(SelectionEvent e) {
setChanged();
}
});
lastControl = wCheckServerIdentity;

// Trusted Hosts line
wTrustedHosts =
new LabelTextVar(
variables,
composite,
BaseMessages.getString(PKG, "ActionMail.TrustedHosts.Label"),
BaseMessages.getString(PKG, "ActionMail.TrustedHosts.Tooltip"));
// wTrustedHosts.addModifyListener(lsMod);
BaseMessages.getString(PKG, "MailServerConnectionDialog.TrustedHosts"),
BaseMessages.getString(PKG, "MailServerConnectionDialog.TrustedHosts.Tooltip"));
FormData fdTrustedHosts = new FormData();
fdTrustedHosts.left = new FormAttachment(0, 0);
fdTrustedHosts.top = new FormAttachment(lastControl, 2 * margin);
fdTrustedHosts.top = new FormAttachment(lastControl, 0);
fdTrustedHosts.right = new FormAttachment(100, 0);
wTrustedHosts.setLayoutData(fdTrustedHosts);
lastControl = wTrustedHosts;

Label wlUseProxy = new Label(composite, SWT.RIGHT);
PropsUi.setLook(wlUseProxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public class MailDialog extends BaseTransformDialog {

private TextVar wMessageOutputField;

private Button wCheckServerIdentity;
private Label wlCheckServerIdentity;
private LabelTextVar wTrustedHosts;

private boolean getPreviousFields = false;

private final MailMeta input;
Expand Down Expand Up @@ -730,7 +734,7 @@ public void focusGained(FocusEvent e) {
// ///////////////////////////////////////

// ////////////////////////////////////
// START OF AUTHENTIFICATION GROUP
// START OF AUTHENTICATION GROUP
// ////////////////////////////////////

Group wAuthentificationGroup = new Group(wContentComp, SWT.SHADOW_NONE);
Expand Down Expand Up @@ -914,6 +918,45 @@ public void widgetSelected(SelectionEvent e) {
}
});

// Use check server identity
wlCheckServerIdentity = new Label(wAuthentificationGroup, SWT.RIGHT);
wlCheckServerIdentity.setText(BaseMessages.getString(PKG, "Mail.CheckServerIdentity.Label"));
PropsUi.setLook(wlCheckServerIdentity);
FormData fdlCheckServerIdentity = new FormData();
fdlCheckServerIdentity.left = new FormAttachment(0, 0);
fdlCheckServerIdentity.top = new FormAttachment(wSecureConnectionType, 2 * margin);
fdlCheckServerIdentity.right = new FormAttachment(middle, -margin);
wlCheckServerIdentity.setLayoutData(fdlCheckServerIdentity);
wCheckServerIdentity = new Button(wAuthentificationGroup, SWT.CHECK);
PropsUi.setLook(wCheckServerIdentity);
FormData fdCheckServerIdentity = new FormData();
fdCheckServerIdentity.left = new FormAttachment(middle, margin);
fdCheckServerIdentity.top = new FormAttachment(wlCheckServerIdentity, 0, SWT.CENTER);
fdCheckServerIdentity.right = new FormAttachment(100, 0);
wCheckServerIdentity.setLayoutData(fdCheckServerIdentity);
wCheckServerIdentity.addSelectionListener(
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setSecureConnectiontype();
input.setChanged();
}
});

// Trusted Hosts line
wTrustedHosts =
new LabelTextVar(
variables,
wAuthentificationGroup,
BaseMessages.getString(PKG, "Mail.TrustedHosts.Label"),
BaseMessages.getString(PKG, "Mail.TrustedHosts.Tooltip"));
wTrustedHosts.addModifyListener(lsMod);
FormData fdTrustedHosts = new FormData();
fdTrustedHosts.left = new FormAttachment(0, 0);
fdTrustedHosts.top = new FormAttachment(wlCheckServerIdentity, 2 * margin);
fdTrustedHosts.right = new FormAttachment(100, 0);
wTrustedHosts.setLayoutData(fdTrustedHosts);

FormData fdAuthentificationGroup = new FormData();
fdAuthentificationGroup.left = new FormAttachment(0, margin);
fdAuthentificationGroup.top = new FormAttachment(wServerGroup, margin);
Expand Down Expand Up @@ -2102,6 +2145,7 @@ public void widgetSelected(SelectionEvent arg0) {
setDynamicZip();
setZip();
setUseAuth();
setSecureConnectiontype();
activateIsAttachContentField();
setOutputMessage();
input.setChanged(changed);
Expand Down Expand Up @@ -2376,6 +2420,8 @@ private void setEnabledEncoding() {
protected void setSecureConnectiontype() {
wSecureConnectionType.setEnabled(wUseSecAuth.getSelection());
wlSecureConnectionType.setEnabled(wUseSecAuth.getSelection());
wTrustedHosts.setEnabled(wUseSecAuth.getSelection());
wCheckServerIdentity.setEnabled(wUseSecAuth.getSelection());
}

private void setEncodings() {
Expand Down Expand Up @@ -2500,6 +2546,7 @@ public void getData() {
}

wUseAuth.setSelection(input.isUsingAuthentication());
wCheckServerIdentity.setSelection(input.isCheckServerIdentity());
wUseXOAUTH2.setSelection(input.isUseXOAUTH2());
wUseSecAuth.setSelection(input.isUsingSecureAuthentication());
if (input.getAuthenticationUser() != null) {
Expand All @@ -2508,7 +2555,9 @@ public void getData() {
if (input.getAuthenticationPassword() != null) {
wAuthPass.setText(input.getAuthenticationPassword());
}

if (!Utils.isEmpty(input.getTrustedHosts())) {
wTrustedHosts.setText(input.getTrustedHosts());
}
wOnlyComment.setSelection(input.isOnlySendComment());

wUseHTML.setSelection(input.isUseHTML());
Expand Down Expand Up @@ -2645,6 +2694,8 @@ private void ok() {
input.setOnlySendComment(wOnlyComment.getSelection());
input.setUseHTML(wUseHTML.getSelection());
input.setUsePriority(wUsePriority.getSelection());
input.setCheckServerIdentity(wCheckServerIdentity.getSelection());
input.setTrustedHosts(wTrustedHosts.getText());

input.setEncoding(wEncoding.getText());
input.setPriority(wPriority.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public class MailMeta extends BaseTransformMeta<Mail, MailData> {

private String messageOutputField;

private boolean checkServerIdentity;
private String trustedHosts;

public MailMeta() {
super(); // allocate BaseTransformMeta
}
Expand Down Expand Up @@ -199,6 +202,9 @@ private void readData(Node transformNode) {
setContactPhone(XmlHandler.getTagValue(transformNode, "contact_phone"));
setComment(XmlHandler.getTagValue(transformNode, "comment"));
setIncludingFiles("Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, "include_files")));
setCheckServerIdentity(
"Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, "checkServerIdentity")));
setTrustedHosts(XmlHandler.getTagValue(transformNode, "trustedHosts"));
setUsingAuthentication("Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, "use_auth")));
setUseXOAUTH2("Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, "usexoauth2")));
setUsingSecureAuthentication(
Expand Down Expand Up @@ -320,6 +326,10 @@ public String getXml() throws HopException {
.append(CONST_SPACE)
.append(XmlHandler.addTagValue("sourcewildcard", this.sourcewildcard));
retval.append(CONST_SPACE).append(XmlHandler.addTagValue("contact_person", this.contactPerson));
retval
.append(CONST_SPACE)
.append(XmlHandler.addTagValue("checkServerIdentity", checkServerIdentity));
retval.append(CONST_SPACE).append(XmlHandler.addTagValue("trustedHosts", trustedHosts));
retval.append(CONST_SPACE).append(XmlHandler.addTagValue("contact_phone", this.contactPhone));
retval.append(CONST_SPACE).append(XmlHandler.addTagValue("comment", this.comment));
retval.append(CONST_SPACE).append(XmlHandler.addTagValue("include_files", this.includingFiles));
Expand Down Expand Up @@ -464,6 +474,22 @@ public void setAttachContentFileNameField(String attachContentFileNameField) {
this.attachContentFileNameField = attachContentFileNameField;
}

public boolean isCheckServerIdentity() {
return checkServerIdentity;
}

public void setCheckServerIdentity(boolean checkServerIdentity) {
this.checkServerIdentity = checkServerIdentity;
}

public String getTrustedHosts() {
return trustedHosts;
}

public void setTrustedHosts(String trustedHosts) {
this.trustedHosts = trustedHosts;
}

public void setDynamicWildcard(String dynamicwildcard) {
this.dynamicWildcard = dynamicwildcard;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ MailServerConnectionDialog.UseProxy=Use proxy?
MailServerConnectionDialog.ProxyUsername=Proxy username
MailServerConnectionDialog.ProxyPassword=Proxy password
MailServerConnectionDialog.ConnectionProtocol=Connection protocol
MailServerConnectionDialog.CheckServerIdentity=Check server identity?
MailServerConnectionDialog.TrustedHosts=Trusted hosts\:
MailServerConnectionDialog.TrustedHosts.Tooltip=Insert the list of trusted hosts separated by a space\
\nExample\: host1 host2 host3
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,7 @@ MailMeta.CheckResult.TransformRecevingData2=Transform is receiving info from oth
MailMeta.CheckResult.ZipfilenameEmpty=Attached zipfilename is empty\!
MailMeta.CheckResult.ZipfilenameOk=Attached zipfilename is specified.
MailMeta.keyword=mail
Mail.CheckServerIdentity.Label=Check server identity?
Mail.TrustedHosts.Label=Trusted hosts\:
Mail.TrustedHosts.Tooltip=Insert the list of trusted hosts separated by a space\
\nExample\: host1 host2 host3
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ MailMeta.CheckResult.TransformRecevingData=Il transform \u00E8 connesso al prece
MailMeta.CheckResult.TransformRecevingData2=Il transform sta ricevendo informazioni dagli altri transforms.
MailMeta.CheckResult.ZipfilenameEmpty=Il nome file Zip allegato \u00E8 vuoto\!
MailMeta.CheckResult.ZipfilenameOk=Il nome file Zip allegato \u00E8 stato specificato.
Mail.TrustedHosts.Label=Hosts affidabili\:
Mail.TrustedHosts.Tooltip=Riempi la lista degli hosts affidabili separandoli con uno spazio\
\nEsempio\: host1 host2 host3
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ ActionMail.ZipFilename.Label=Name of zip archive
ActionMail.ZipFilename.Tooltip=Name of zip archive
ActionMail.ZipFiles.Label=Zip files to single archive
ActionMailDialog.Server.Label=Server
ActionMail.Group.ConnectionGroup.Label=Mail Server Connection
ActionMail.Group.ConnectionGroup.Label=Mail Server Connection
ActionMail.CheckServerIdentity.Label=Check server identity?
ActionMail.TrustedHosts.Label=Trusted hosts\:
ActionMail.TrustedHosts.Tooltip=Insert the list of trusted hosts separated by a space\
\nExample\: host1 host2 host3
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ ActionMail.ZipFilename.Label=Nome dell''archivio ZIP:
ActionMail.ZipFilename.Tooltip=Nome dell''archivio ZIP
ActionMail.ZipFiles.Label=Comprimere i file in un solo archivio?
ActionMailDialog.Server.Label=Server
ActionMail.TrustedHosts.Label=Hosts affidabili\:
ActionMail.TrustedHosts.Tooltip=Riempi la lista degli hosts affidabili separandoli con uno spazio\
\nEsempio\: host1 host2 host3
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@
package org.apache.hop.workflow.actions.mail;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.hop.core.ResultFile;
import org.apache.hop.junit.rules.RestoreHopEngineEnvironment;
import org.apache.hop.pipeline.transforms.loadsave.validator.ArrayLoadSaveValidator;
import org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator;
import org.apache.hop.pipeline.transforms.loadsave.validator.IntLoadSaveValidator;
import org.apache.hop.pipeline.transforms.loadsave.validator.PrimitiveIntArrayLoadSaveValidator;
import org.apache.hop.pipeline.transforms.loadsave.validator.StringLoadSaveValidator;
import org.apache.hop.workflow.action.loadsave.WorkflowActionLoadSaveTestSupport;
import org.junit.ClassRule;

Expand Down Expand Up @@ -73,25 +64,24 @@ protected List<String> listAttributes() {
"replyToAddresses",
"fileType",
"embeddedimages",
"contentids"
);
"contentids");
}

/*
@Override
protected Map<String, IFieldLoadSaveValidator<?>> createAttributeValidatorsMap() {
Map<String, IFieldLoadSaveValidator<?>> validators = new HashMap<>();
validators.put(
"fileType",
new PrimitiveIntArrayLoadSaveValidator(
new IntLoadSaveValidator(ResultFile.fileTypeCode.length)));
/*
@Override
protected Map<String, IFieldLoadSaveValidator<?>> createAttributeValidatorsMap() {
Map<String, IFieldLoadSaveValidator<?>> validators = new HashMap<>();
validators.put(
"fileType",
new PrimitiveIntArrayLoadSaveValidator(
new IntLoadSaveValidator(ResultFile.fileTypeCode.length)));
int entries = new Random().nextInt(20) + 1;
validators.put(
"embeddedimages", new ArrayLoadSaveValidator<>(new StringLoadSaveValidator(), entries));
validators.put(
"contentids", new ArrayLoadSaveValidator<>(new StringLoadSaveValidator(), entries));
return validators;
}
*/
int entries = new Random().nextInt(20) + 1;
validators.put(
"embeddedimages", new ArrayLoadSaveValidator<>(new StringLoadSaveValidator(), entries));
validators.put(
"contentids", new ArrayLoadSaveValidator<>(new StringLoadSaveValidator(), entries));
return validators;
}
*/
}

0 comments on commit b2c6178

Please sign in to comment.