Appendix A, Programming Tips

4D - Documentation   Français   English   German   Japanese   4D Internet Commands, Theme List   4D Internet Commands, Alphabetical List   Back   Previous   Next

version 6.5


Executing Commands via a Case Statement

In many of the examples in this document, a programming construct is used which is likely to be unfamiliar to many developers. Many of these examples execute a series of commands as falsified cases within a 4th Dimension Case statement.

Many of the commands within 4D Internet Commands require that an entire sequence of commands execute successfully in order to complete. Since the failure of any one command within the sequence should stop any further processing along that path, it would become laborious to cascade your If conditions many level deeps:

   If (SMTP_New($smtp_id)=0)
      If (SMTP_Host ($smtp_id;<>pref_Server)=0)
         If (SMTP_From ($smtp_id;vFrom)=0)
            If (SMTP_To ($smtp_id;vTo)=0)
               …and deeper, and deeper…
            End if
         End if
      End if
   End if

An alternative to this method is to rely on the manner in which 4D executes it's case statements. Each item of a case statement is executed by 4D in order to determine if its return value is True or False. If all elements of a case statement were to return a false value, then each element of that case statement's tests would have been run. We can execute the same code described above by the following:

   $SentOK:=False  `A flag to indicate if we made it through all of the calls
   Case of 
      : (SMTP_New ($smtp_id)#0)
      : (SMTP_Host ($smtp_id;<>pref_Server)#0)
      : (SMTP_From ($smtp_id;vFrom)#0)
      : (SMTP_To ($smtp_id;vTo)#0)
      : (SMTP_Subject ($smtp_id;vSubject)#0)
      : (SMTP_Body ($smtp_id;vMessage)#0)
        : (SMTP_Send ($smtp_id)#0)
   Else 
      $SentOK:=True  `message was composed and mailed successfully
   End case 
   If ($smtp_id#0)  `If a Message Envelope was created we should clear it now
      $OK:=SMTP_Clear ($smtp_id)
   End if 

In the above example, every 4D Internet command will return a zero error number if it successfully completed. In order for 4D to evaluate each case statement, it must actually execute each external call to obtain its return value. Since each case element compares the return result to not zero, 4th Dimension will not find an element to stop on until one of the commands fails. If every command executes successfully, 4D will proceed down to run the Else condition where we set the $SentOK flag to indicate that the message was composed and sent successfully.

Suggestions when auto-replying to POP3 or IMAP mail

If you are planning on implementing a mail system within your database in which the user can "Reply" to mail they have received, there are some standard suggestions for how to fill out the fields of the reply message. The following suggestions are outlined by RFC#822:

The address listed in the "Sender" field should receive notices of any problems during delivery of the initial messages. If no "Sender" field exists, notices should be sent to the address listed in the "From" field. The "Sender" mail address should only be sent replies pertaining to problems in the mail delivery and not replies related to the topic of the message.

The "Sender" address should never be used in an automated process of replying to messages. Instead, the message should either use the "Reply-To" field or the "From" field, dependent on the conditions described below.

If the "Reply-To" field exists and contains one or more mail addresses, then any reply should be directed to the people in that list. Addresses within the "Reply-To" header override any addresses listed in the "From" header. However, if no "Reply-To" field exists but a "From" field does exist, replies should be sent to the mailbox(es) indicated in the "From" header.

These suggestions are only meant to help the decision process when the mail addressing is programmatically handled in the case of "Reply" type actions. Once the Reply message has been created, the end-user can certainly override any of these defaults before sending the message.


4D - Documentation   Français   English   German   Japanese   4D Internet Commands, Theme List   4D Internet Commands, Alphabetical List   Back   Previous   Next