Ivan,

I don't understand your question?

Looking at the code...

if (this.sender == null) {
    this.sender = this.marshaler != null
                ? this.marshaler.getDefaultSenderForOutgoingMails() : 
AbstractMailMarshaler.DEFAULT_SENDER;
        }

Given the situation, a marshaler returns NULL on method 
getDefaultSenderForOutgoingMails() you would run into a NPE without this 
check. So this check is absolute needed here.

Regards
Lars





Am Montag 13 Oktober 2008 12:56:41 schrieb ivan:
> Hi Lars!
>
> All shown code has check on Null:
>
> <<<
> if (from != null) {
>    mimeMessage.setFrom(from);
> }
>
>
>
> As far as I understood, anyway "from" is set either from "this.sender"
> or "this.marshaler.getDefaultSenderForOutgoingMails()".
> So, we can not get situation (from==null). It is correct?
>
> Ivan Pryvalov.
>
> Lars Heinemann пишет:
> > Ivan,
> >
> > you only look at one aspect of the logic.
> > Please have a look at the DefaultMailMarshaler class.
> >
> >     protected void fillMailHeaders(MimeMessage mimeMessage,
> > MessageExchange exchange,
> >                                    NormalizedMessage nmsg, String
> > configuredSender, String configuredReceiver)
> >         throws Exception {
> >
> >         ...
> >
> >         // fill the "From" field of the mail
> >         if (configuredSender != null && configuredSender.trim().length()
> > > 0) { // if sender is configured through xbean then use it Address from
> > = InternetAddress.parse(configuredSender)[0]; if (from != null) {
> >                 mimeMessage.setFrom(from);
> >             }
> >         } else if (nmsg.getProperty(AbstractMailMarshaler.MSG_TAG_FROM)
> > != null) {
> >             // use the delivered From field from the message
> >             Address from =
> > InternetAddress.parse(nmsg.getProperty(AbstractMailMarshaler.MSG_TAG_FROM
> >) .toString())[0];
> >             if (from != null) {
> >                 mimeMessage.setFrom(from);
> >             }
> >         } else {
> >             // there was no From field delivered, so use the default
> > sender Address from =
> > InternetAddress.parse(getDefaultSenderForOutgoingMails())[0];
> >             if (from != null) {
> >                 mimeMessage.setFrom(from);
> >             }
> >         }
> >
> >         ...
> >
> >
> > I hope this makes it more clear to you. If you write your own marshaler,
> > then you are also responsible for filling the mail properties correctly.
> > When using the default marshaler, all should work fine if you did it
> > correct.
> >
> > Regards
> > Lars
> >
> > Am Freitag 10 Oktober 2008 15:30:05 schrieb ivan:
> >> Hi!
> >>
> >> I read at http://servicemix.apache.org/servicemix-mail.html:
> >>
> >> <<<
> >> How is the sender determined?
> >>
> >> if there is a preconfigured sender for the endpoint from xbean.xml, it
> >> will be used
> >> else if MSG_TAG_FROM is defined in the message properties, then it will
> >> be used
> >> else the method getDefaultSender() of the marshaler is invoked
> >>
> >>
> >>
> >> Also I looked at the source (I downloaded it some month ago from
> >> 3.3-SNAPSHOT):
> >>
> >> <<< MailSenderEndpoint.java
> >>
> >>      public void validate() throws DeploymentException {
> >>          super.validate();
> >>
> >>          if (this.config == null || this.connection == null) {
> >>              throw new DeploymentException("No valid connection uri
> >> provided.");
> >>          }
> >>          if (this.sender == null) {
> >>              this.sender = this.marshaler != null
> >>                  ? this.marshaler.getDefaultSenderForOutgoingMails() :
> >> AbstractMailMarshaler.DEFAULT_SENDER;
> >>          }
> >>      }
> >>
> >>
> >>
> >> So, it seems, there is no way to configure "sender" header for e-mail
> >> via MSG_TAG_FROM.
> >>
> >> Am I right? Or maybe it is already fixed?
> >>
> >> Truly yours,
> >> Ivan Pryvalov.

Reply via email to