The Swift Mailer module installs the Swift Mailer library as Drupal's default mail system. It is capable of sending e-mails via SMTP, a locally installed MTA and PHP's built in mail() function.

The module provides the following features :

  • Your modules can specify file(s) that are either to be added to an e-mail as attachment(s) or inline image(s) though the hook_mail_alter().
  • You can theme e-mails according to your site's theme through an e-mail theme file. Images that takes part in the layout can be added to the e-mail as inline images.
  • You can choose the default e-mail format that is to be used in e-mails (plain text or HTML).

My motivation for creating the module was that I configured Drupal on a server which was not set up to handle e-mail. E-mail could not be set up on the server, and I had to find a way to send e-mails using SMTP. Furthermore, I've always missed an easy way of being able to add attachments (both standard attachments and inline image attachments) to e-mails sent from Drupal. This module is capable of doing both.

I am not in any way affiliated with the actual Swift Mailer library.

http://drupal.org/sandbox/sbrattla/1163884

Reviews of Other Projects

24/03/2012
http://drupal.org/node/1488834#comment-5778372
http://drupal.org/node/1488292#comment-5778424 (not a real review, but at least some hopefully valuable feedback)
http://drupal.org/node/1392210#comment-5778500 (not a real review either, but feedback on module design)

25/03/2012
http://drupal.org/node/1488292#comment-5780510

26/03/2012
http://drupal.org/node/1488292#comment-5782670
http://drupal.org/node/1488292#comment-5782692

11/05/2012
http://drupal.org/node/1074342#comment-5983568
http://drupal.org/node/1488292#comment-5983628
http://drupal.org/node/1392144#comment-5983668

CommentFileSizeAuthor
#52 drupalcs-result.txt5.78 KBklausi
#39 drupalcs-result.txt6.31 KBklausi

Comments

sbrattla’s picture

I would be greatful if someone would have a few moments to take a look at my project and give me a little feedback as to whether there are things i need to correct.

pillarsdotnet’s picture

Status: Needs review » Needs work

Consider running your entire module through Coder Review.

README.txt
Needs to be properly word-wrapped at space characters, rather than blindly inserting a linefeed in the middle of words.
swift_mailer.info
It might be better to name your module swiftmailer rather than swift_mailer so as to avoid overlapping namespaces with a future module named swift.
Change package = E-mail to package = Mail to be consistent with other mail-sending modules.
Class include files should be listed in a files[] section. See http://drupal.org/node/542202
Module configuration path should be listed in a configuration line.
Needs a trailing linefeed
swift_mailer.install
If you want to create a new variable name, it should be prefixed by your module name. So mail_system_old should be swift_mailer_mail_system_old.
For proper handling of the mail_system variable, see http://drupal.org/node/900794#comment-4160574
See http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_uninstall/7#comment-15344
swift_mailer.module
Class include files should be autoloaded. See http://drupal.org/node/542202
Please explain the reasoning behind the plethora of constant declarations.
includes/classes/SWIFTMailSystem.inc
The format() function incorrectly assumes that $message['body'] always exists and always contains an array.
All message formatting should be performed by the format() function. Your code appears to add attachments, etc. in the mail() function, which should only be responsible for delivery of the formatted message.
The "\r\n" string should be replaced by variable_get('mail_line_endings', MAIL_LINE_ENDINGS)
Consider integrating with Libraries API rather than reinventing the wheel.
Consider spelling $supressable as $suppressable.
Consider correcting All attachments needs to to All attachments need to.
Consider combining separate but closely-related configuration variables into a single array variable.
Dynamic values in watchdog() errors should be added via the $variables parameter rather than being concatenated into the $message parameter.
includes/helpers/conversion.inc
Using a constant for your date pattern prevents the possibility of translation.
Consider spelling parametrized as parameterized in function names, as you already do in their respective comment blocks.
Remove blank lines between subsequent @param declarations. See http://drupal.org/node/1354#functions
The @param declaration should match the function signature. (e.g., @param Swift_Message $message should be followed by function swift_mailer_foo(Swift_Message $message,.)
Consider spelling excact as exact.
See also (@see) sections should generally be at the documentation header.
Documentation headers for swift_mailer_is_id_header() and swift_mailer_is_path_header() are confusingly similar, and don't seem to match the code.
Consider wrapping all the is_foo_header() and add_foo_header() functions by a single add_header() function.
includes/helpers/utilities.inc
Consider spelling prodived as provided.
Again, consider integrating with Libraries API rather than reinventing the wheel.
includes/pages/swift_mailer_page_admin_config_swift_mailer_default.inc
The usual practice would be to name this file swift_mailer.admin.inc.
Missing @file header. See http://drupal.org/node/1354
Missing or incomplete function documentation headers.
Consider using shorter function names, for readability. It is enough to prefix the function name with your module name; you don't have to include the path as well.

I think that's enough for now.

sbrattla’s picture

Thanks a lot for your reply! Everything makes sense and I will have a look at things as quick as possible!

cyberwolf’s picture

Subscribing.

wjaspers’s picture

Subbing. @crell discussed the need for a standard mail library at #dctc 2011. This might be just the ticket!

cchan’s picture

subscribing.

sbrattla’s picture

Activity has been a little low during the summer, but I am hoping to get back on track and get a release ready soon.

As it is right now, this module "replaces" the default mail system with a custom mail system implementation. This is by design, as the intention is to have SwiftMailer take care of all e-mail handling. When the module gets uninstalled, the original mail system will be set back in business. I can't really see if it makes sense to let Drupal use several mail systems at the same time. This would mean that one would have to choose the 'default' system, and other modules could then choose which one of the available mail systems to use. However, I can't really see where this would make sense. If someone thinks that it is a bad idea to have swiftmailer replace the original mail system, then i'd love to hear about it.

sbrattla’s picture

Status: Needs work » Needs review

Things have been a little quiet during the summer, but I've finally found time to look a little at the module again. I've gone through the feedback given by 'pillarsdotnet' and corrected the things which made sense to correct. I've added the original feedback with my comments below.

All feedback is welcome, and I will do my best to make this module as good as it can get.

README.txt
Needs to be properly word-wrapped at space characters, rather than blindly inserting a linefeed in the middle of words.

I've done my best to clean up the README.txt file.

swift_mailer.info
It might be better to name your module swiftmailer rather than swift_mailer so as to avoid overlapping namespaces with a future module named swift.
Change package = E-mail to package = Mail to be consistent with other mail-sending modules.
Class include files should be listed in a files[] section. See http://drupal.org/node/542202
Module configuration path should be listed in a configuration line.
Needs a trailing linefeed
  • I've renamed the module from swift_mailer to swiftmailer.
  • Package has been changed from E-mail to Mail.
  • The SwiftMailSystem class has been included in the files[] array, and I've added the configuration path.
  • I've added a trailing linefeed.
swift_mailer.install
If you want to create a new variable name, it should be prefixed by your module name. So mail_system_old should be swift_mailer_mail_system_old.
For proper handling of the mail_system variable, see http://drupal.org/node/900794#comment-4160574
See http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_uninstall/7#comment-15344
  • Variable names have been prefixed with swiftmailer.
  • I have read the documentation regarding proper handling of the mail system, but it is by design that this module replaces the original mail system. It puts the original mail system back in business when the module is uninstalled. The module was born out of a need to have a mail system which is capable of handling attachments and HTML mails withouth having to think about the details. Thus, it was thought in the first place to be used as a replacement for the default mail system. I am not opposed to having several mail systems living side by side, but the idea was to have it replace the default one and take care of all e-mail handling.
swift_mailer.module
Class include files should be autoloaded. See http://drupal.org/node/542202
Please explain the reasoning behind the plethora of constant declarations.
  • The SwiftMailSystem is now autoloaded (as it has been included in the .info file). /li>
  • The reason for having all the constant declarations is to make it easier to maintain and get an overview of the variables in use. Coming from a Java background, i like knowing wich variables exist and like the overview it gives. This also gives me better overview from a maintenance perspective when, say, i want to make sure that all variables in use by the module is deleted when the module is uninstalled. I hardly believe that it is best practice to avoid declarations?
includes/classes/SWIFTMailSystem.inc
The format() function incorrectly assumes that $message['body'] always exists and always contains an array.
All message formatting should be performed by the format() function. Your code appears to add attachments, etc. in the mail() function, which should only be responsible for delivery of the formatted message.
The "\r\n" string should be replaced by variable_get('mail_line_endings', MAIL_LINE_ENDINGS)

Consider integrating with Libraries API rather than reinventing the wheel.
Consider spelling $supressable as $suppressable.
Consider correcting All attachments needs to to All attachments need to.
Consider combining separate but closely-related configuration variables into a single array variable.
Dynamic values in watchdog() errors should be added via the $variables parameter rather than being concatenated into the $message parameter.
  • The format() function now checks $message['body'].
  • My code does add attachments, but this is due to the fact that the actual message is ceated in the mail() function, and attachments needs to be added there. I can't see that it makes sense to create the Swift_Message instance in format(), as the purpose of that function is just to format the message. It was thus decided to first instantiate the Swift_Message in format(), and that consequently resulted in attachments to be added here too.
  • Line breaks as '\r\n' have been replaced with variable_get('mail_line_endings', MAIL_LINE_ENDINGS).
  • I'll look at integration with the Libraries API. However, there's not much code involved in checking where the library is, and my initial thought is that it might be a little overkill to tell people to install another module just for a basic check.
  • Various spelling mistakes have been corrected.
  • Corrected calls to watchdog to allow dynamic values.
includes/helpers/conversion.inc
Using a constant for your date pattern prevents the possibility of translation.
Consider spelling parametrized as parameterized in function names, as you already do in their respective comment blocks.
Remove blank lines between subsequent @param declarations. See http://drupal.org/node/1354#functions
The @param declaration should match the function signature. (e.g., @param Swift_Message $message should be followed by function swift_mailer_foo(Swift_Message $message,.)
Consider spelling excact as exact.
See also (@see) sections should generally be at the documentation header.
Documentation headers for swift_mailer_is_id_header() and swift_mailer_is_path_header() are confusingly similar, and don't seem to match the code.
Consider wrapping all the is_foo_header() and add_foo_header() functions by a single add_header() function.
  • The constant for date patterns is used to discover patterns in a provided value. It should not be translated.
  • Spelling mistakes corrected
  • Blank lines between @see declarations have been removed.
  • Function signatures now include Swift_Message to conform with documentation.
  • I agree that swift_mailer_is_id_header and swift_mailer_is_path_header() looks
    very similar, but there is an important difference. Swift Mailer operates by distinguishing these header types, and i need to be able to parse headers provided by Drupal and "convert" them to the appropriate Swift Mailer headers. These functions take care of that
  • I could add a add_header() function. However, a piece of code in SwiftMailSystem takes care of this in the same fashion as that function would. However, it's a good idea with regard to making SwiftMailSystem more lean and clean and not taking on more than a single responsibility - send e-mails.
  • includes/helpers/utilities.inc
    Consider spelling prodived as provided.
    Again, consider integrating with Libraries API rather than reinventing the wheel.
    • Fixed spelling mistakes
    includes/pages/swift_mailer_page_admin_config_swift_mailer_default.inc
    The usual practice would be to name this file swift_mailer.admin.inc.
    Missing @file header. See http://drupal.org/node/1354
    Missing or incomplete function documentation headers.
    Consider using shorter function names, for readability. It is enough to prefix the function name with your module name; you don't have to include the path as well.
    • File and function names have been shortened
    • the @file header added.
    sbrattla’s picture

    Added support for theming, and spent quite a bit of time documenting how e-mails can be themed. Hooks which lets other themes and modules embed inline images and add attachments have been implemented too.

    demerzel’s picture

    Subbing. @sbrattla: you saved my day, keep up the good work. Hope to see a stable version soon.

    sbrattla’s picture

    Priority: Normal » Major

    I'd really appreciate if someone would have the chance to devote a little time to review my module. I'm using the module myself on a couple of sites, and it seems to be working fine. I've done my best to correct things according to the feedback I've received here, and I've also run the module through the coders review module.

    However, I'm not really getting anywhere before i get feedback from others. I'm thus changing the priority to 'Major', as the 'What To Expect' document states that I am 'allowed' to do this if I have not received feedback for 2 weeks.

    Again, I'd really appreciate if anyone would have the chance to give me a little feedback.

    klausi’s picture

    Priority: Major » Normal
    Status: Needs review » Needs work

    * git release branch is missing, see http://drupal.org/node/1015226
    * CHANGELOG.TXT should be CHANGELOG.txt
    * same for README.txt
    * info file contains wrong line endings ('\r'), you must use unix line endings, see http://drupal.org/node/318#indenting
    * info file: only files should be listed there that contain classes or interfaces
    * install file: hook doc blocks on functions are missing
    * install file, module file: indentation should be 2 spaces only.
    * module file misses @file doc block, see http://drupal.org/node/1354#files
    * swiftmailer_menu(): doc block format is not correct, see http://drupal.org/node/1354#hookimpl
    * you have committed your netbeans project settings folder. Remove it from the repository.

    Anonymous’s picture

    Except if I'm mistaken you should implement hook_perm in order to be able to give the administer permission to some groups.

    Otherwise this module seems to be a good idea!

    sbrattla’s picture

    @Vcnt : I've assumed that the module will be administered by site Administrators, and have thus chosen not to implement any privileges which can be assigned to roles.

    @klausi : I've done my best to correct things outlined by you. The module has also been run through the Coder module, and I've
    tried to correct more or less most things outlined by it.

    The module have now been upgraded to better support theming. E-mails are themed using Drupal's theme() function. The key hook 'swiftmailer' can be used to theme e-mails. The module also comes with improved support for adding files specified in theme files. This should hopefully make life easier for themers, as adding an inline file to an e-mail now will be a matter of writing <img src="image:/path/to/file" />.

    All further reviews are welcome!

    sbrattla’s picture

    Status: Needs work » Needs review

    I'm changing the status from 'needs work' to 'needs review' as I need someone to review the work I've done from the various comments I've received.

    sbrattla’s picture

    Priority: Normal » Major

    I'm upgrading priority to 'major' as no response has been received on my last posts for 2 - 3 weeks. I'd really appreciate if someone have the time to look at the module.

    sbrattla’s picture

    Hi,

    I'd just like to hear if I am doing anything 'wrong' with regards to the process of getting new modules approved? It's been more than a month since i commited the last changes. Please don't take this as a 'complaint', but as this is my first module I can't really publish the module for real before it's been approved. I'd really like to have the module published as a real project so that anyone interested can start using it. I'd also say it is a good way to get more feedback on it, and improve it according to that feedback.

    klausi’s picture

    No, you are not doing anything wrong. We are currently running short on reviewers, so it can take up to 4-5 weeks until you get another review (I'm working the issue queue backwards from the oldest updated date).

    You can speed up the process by reviewing other project applications, so we can get back to yours sooner. You can also get in touch with other community members that might be interested in your project and ask them for a review. http://drupal.org/community

    chrisroane’s picture

    --------------
    MANUAL REVIEW
    --------------

    1) When I first installed the module, and have the swiftmailer in sites/all/libraries/ ....it still requires a path to the library to be specified under /admin/config/swiftmailer/ . When I enter "sites/all/libraries/swiftmailer" into the field, the error goes away. Can you default this in detecting this path automatically and if it it doesn't find it there, then display the error?

    2) Should we make the password field under the Transport tab a "password" type text field? I know in some cases clients may not want their password displayed in plain text to see for those who have access to that admin area.

    3) On the Transport tab, when the settings are saved, can you have the system validate the information to make sure it is correct? Maybe send a test email? This would help tremendously in debugging why things aren't working, or when the settings have changed.

    4) I tried to send out a test email, but I received this error: Parse error: syntax error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /Users/chrisroane/Sites/acquia-drupal/sites/default/modules/swiftmailer/includes/classes/SWIFTMailSystem.inc on line 200

    ------------
    AUTO REVIEW
    ------------
    It appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.
    Review of the master branch:

    • Remove "version" from the info file, it will be added by drupal.org packaging automatically.
    • ./includes/helpers/conversion.inc: all functions should be prefixed with your module/theme name to avoid name clashes. See http://drupal.org/node/318#naming
      function swift_mailer_add_date_header(Swift_Message $message, $key, $value) {
      
    • Bad line endings were found, always use unix style terminators. See http://drupal.org/coding-standards#indenting
      ./swiftmailer.info:                               ASCII English text, with CRLF line terminators
      swiftmailer.info
      
    • Run coder to check your style, some issues were found (please check the Drupal coding standards). See attachment.
    • Drupal Code Sniffer has found some code style issues (please check the Drupal coding standards). See attachment.

    This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.

    There are quite a few other issues with your code, that doesn't meet the drupal standards. Here is a complete list: http://ventral.org/pareview/httpgitdrupalorgsandboxsbrattla1163884git

    I suggest using the automatic review tool to resolve all of the issues.

    chrisroane’s picture

    Status: Needs review » Needs work

    Forgot to change the status to needs work.

    sbrattla’s picture

    Status: Needs work » Needs review

    Thanks for your feedback!

    1. The module now scans the /sites/all/libraries directory and attempts to find the Swift Mailer library if not provided.
    2. The password field is now a "real" password field
    3. Not sure how to validate things here, and not sure if it is a good idea to send a test e-mail every time save is clicked?
    4. I believed the last issue you experiences has been fixed. My original code relied on PHP 5.3 functionality.

    With regards to the 'master' branch, this is something I'm working on. However, it has become quite messy as I've been trying to move everything over to a different branch, but git is giving me a hard time so I just need a little more time getting it right.

    Furthermore, I've run the code through the review site quite a few times now and corrected things to the best of my effort. However, there are a few things remaining. They should not be 'release blockers' though (an indentation of 6 instead of 4 would not be a release blocker, i presume?)

    chrisroane’s picture

    Status: Needs review » Needs work

    1. You really need to fix the git organization issues before this module is published.

    I'm new to using git as well. But I think you need to create a new branch called: 7.x-1.x. Merge the latest changes into that branch and delete all of the files in the master branch. Then delete the 7.x-1.0-alpha branch (my understanding is that the system will automatically handle the version based on what is in the .info file).

    2. When I have the swiftmailer plugin in /sites/all/libraries, it still displays a form error when no value is in the field on /admin/config/swiftmailer . But maybe this is because the master branch doesn't have the latest files? I grabbed the latest files from the master branch and the password field is still a plain text field.

    3. That's probably right. Maybe having a "Test SMTP" area that allows you to enter a To email address and send one email when clicked? This isn't an absolute need at this point, though. So I created a new issue for this feature: #1432972: Test SMTP Settings.

    4. I took a look at the README.txt file and it has a lot of useful information. However, it seems to be overwhelming with how much is in that file. However, I don't think this is something that has to happen right away. Here is the new feature request I created: #1432986: Simplify README.txt.

    As soon as you can get the git repository organized and setup properly, I will go ahead and test the code and take a closer look at the module. I don't think it is worth working on anything else until you can get this ironed out. I know you have been working on this module for a while (on and off), but I know that this a priority issue that needs to be resolved as soon as possible.

    I'm very interested in helping you maintain this project. But for the time being I'm also trying to get a module through the approval process: #1425392: Splashify. Once I get that through, I would love to become a co-maintainer and help you manage the module. I could see myself using this module all the time.

    sbrattla’s picture

    Hi chrisroane,

    Thanks for your input.

    1. I think I got git right now. I'd really like to have the 'master' branch cleared so that people stay clear of it. However, I can't do it as it appears to be locked. Anyway, the '7.x-1.0-alpha1' branch is now the one I'm working on.

    2. Try checkout out the '7.x-1.0-alpha1' branch. Please let me know if you still have trouble with it.

    3. A 'test'-tab already exists in the administration section. There's a text field where you can enter any e-mail address to which you'd like to send a test e-mail.

    4. README.txt is overwhelming, and I'm hoping to get a documentation page up and running once the project gets approved. I can't find a way to post documentation on the sandbox page. However, good idea. I could make a "QUICK START" section on top, and the an "DEEP DIVE" section where techies can go and find more details about things.

    chrisroane’s picture

    Just to clarify here, you can't actually delete the master branch. You should be able to delete the files that are in it....and that is what I would do.

    I'll take a closer look at the code either tomorrow or Friday.

    sbrattla’s picture

    Cleaned up code through three iterations of automatic reviews.

    chrisroane’s picture

    I grabbed the correct branch.

    1. I verified the Test tab works.

    2. You should be able to delete the files under the Master branch. From my understanding, you can't delete that branch in git. You will want to do this, because it makes it confusing which branch contains the latest code.

    3. I just learned this with my module, but you should use the Libraries module (version 2.0: http://drupal.org/project/libraries ) to include the swiftmailer library. This should make it easier for to get working.

    4. It is my understanding, that you should not include html when sending strings to the t() function. The Drupal 6 documentation describes this much better than the Drupal 7 version: http://api.drupal.org/api/drupal/includes%21common.inc/function/t/6 . I found many of these cases. Example: Line 87 in swiftmailer_admin_transport.inc ... Also lines: 91, 142, 146, 176, etc...This is in pretty much every other PHP file I looked at.

    5. I did test sending out the default contact form, and I received the email.

    sbrattla’s picture

    Thanks for your reply,

    #1. Great to hear that testing works.

    #2. I'll look into the files on the 'master' branch.

    #3. I've looked in to the Libraries module before, and it is probably a good module. However, I am reluctant to making this a requirement. I personally do not like modules that requires me to install all sorts of dependencies, and I also think it is important to consider the fact that if every module would require another module as a dependency you'd end up with a Drupal installation with twice the number of modules you'd actually need. Those modules all slow down you site a little bit. It is thus a choice I've made not to use the Libraries module.

    #4. Thanks, I'll look into HTML and t().

    #5. Great to hear that the e-mail reached you :-)

    chrisroane’s picture

    They requested I use the Libraries module for the module I am trying to get approved, which is why I mentioned it. The good thing about it is that it automatically will detect the library if it is in any of the "site" directories, without having to enter any path in an admin. It also looks like a lot of other modules use it. But I don't know if it is something they will require or not in order to get approved.

    sbrattla’s picture

    The Library module has been mentioned earlier in one of the above posts too, but I don't really see how the module will improve my module other than adding overhead. The library which my module use (Swift Mailer) won't really be used by any other modules, and as it is right now my module also automatically detects the Swift Mailer library if it is in the 'sites/all' directory.

    Thanks for bringing it to attention though, but unless it becomes a "show stopper" I prefer not to make my module depend on it.

    sbrattla’s picture

    - Cleaned up usage HTML tags in t().
    - Removed NetBeans specific project files from GIT.
    - Deleted all files in 'master' branch.

    sbrattla’s picture

    Issue summary: View changes

    Added review of other module.

    sbrattla’s picture

    Priority: Major » Normal
    Status: Needs work » Needs review
    sbrattla’s picture

    Issue summary: View changes

    Added review.

    sbrattla’s picture

    Issue summary: View changes

    Module review.

    exratione’s picture

    EDIT: never mind: I thought you weren't setting the Return Path, but I tested with my Bounce module and it's clear that Swift Mailer is setting the return path. I'll go on to review while I'm here.

    exratione’s picture

    1) Trivial bug in swiftmailer_admin_default.inc

      $form['description'] = array(
        '#markup' => '<p>' . t('The Swift Mailer module replaces the default mail system that is shipped
          with Drupal and installs itself as the primary mail system. This allows
          you to choose how e-mails should be sent. Furthermore, with the Swift
          Mailer module you can easily add attachments to e-mails. To read more
          about how this module works, please have a look at the !documentation.') . '</p>',
      );
    

    Missing a definition for !documention.

    2) Another trivial bug in swiftmailer_admin_transport.inc:

        switch ($form_state['values']['transport']['type']) {
          case SWIFTMAILER_TRANSPORT_SMTP:
            variable_set(SWIFTMAILER_VARIABLE_SMTP_HOST, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['server']);
            variable_set(SWIFTMAILER_VARIABLE_SMTP_PORT, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['port']);
            variable_set(SWIFTMAILER_VARIABLE_SMTP_ENCRYPTION, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['encryption']);
            variable_set(SWIFTMAILER_VARIABLE_SMTP_USERNAME, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['username']);
            variable_set(SWIFTMAILER_VARIABLE_SMTP_PASSWORD, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['password']);
            drupal_set_message(t('Drupal have been configured to send all e-mails using the SMTP transport type.'), 'status');
            break;
          case SWIFTMAILER_TRANSPORT_SENDMAIL:
            variable_set(SWIFTMAILER_VARIABLE_SENDMAIL_PATH, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL]['path']);
            variable_set(SWIFTMAILER_VARIABLE_SENDMAIL_MODE, $form_state['values']['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL]['mode']);
            drupal_set_message(t('Drupal have been configured to send all e-mails using the Sendmail transport type.'), 'status');
            break;
          case SWIFTMAILER_TRANSPORT_NATIVE:
            drupal_set_message(t('Drupal have been configured to send all e-mails using the PHP transport type.'), 'status');
            break;
        }
    

    Replace 'Drupal have been' with 'Drupal has been'.

    3) You don't have to do this:

    drupal_set_message(t('An e-mail has been sent to !email.', array('!email' =>  check_plain($form_state['values']['test']['recipient']))));
    

    when you could do this:

    drupal_set_message(t('An e-mail has been sent to @email.', array('@email' => $form_state['values']['test']['recipient'])));
    

    4) In general, you should probably check all the places you have used !token in strings and make sure that, yes, you really want to pass strings through unchecked. It's generally better security practice, I think, to default to using @token - which will check_plain() - and only then go back and see what has to be let through.

    5) Earlier commenters are right in noting that you'll have to be working in a branch called 7.x-1.x - see how I have things set up in the Bounce module you were reviewing. Actual versioning (e.g. 7.x-1.0-alpha1) is done by using tags, not branches.

    sbrattla’s picture

    In reply to #33 :

    1. The 'trivial bug' has been fixed!
    2. The 'another trivial bug' has been fixed!
    3. and 4. Fixed !token and @token issues where appropriate.
    5. I've created a branch called 7.x-1.x which I now work against.

    Thanks for your feedback.

    exratione’s picture

    1) In the install file: shouldn't the line below be variable_del(SWIFTMAILER_VARIABLE_MAIL_SYSTEM_OLD)?

      // Delete the old mail configuration.
      variable_del('mail_system_old');
    

    2) And in swiftmailer_uninstall(), why not use the variable names you've defined rather than strings? Not a big deal; it isn't broken.

    3) swiftmailer_admin_test.inc, line 69:

     drupal_set_message(t('An e-mail has been sent to @email.', array('!email' =>  $form_state['values']['test']['recipient'])));
    

    That !email should be @email.

    ----

    Aside from that, I'm using Swift Mailer in testing some of my mail-related code that needs an SMTP server involved in the process - this module works and does what it says on the label. It is a favorable alternative to SMTP Authentication Support. Given the rest of this thread, I think it should be set to Reviewed & Tested by the Community.

    sbrattla’s picture

    Hi,

    1. You are absolutely right. The 'mail_system_old' is the old name for that variable. Fixed.
    2. I've had trouble using the defined variable names in the hook_uninstall() function. I've changed things a little in the .install file now so that the actual variable names are being used. A little less clean, but I at least I'm sure it will work.
    3. Fixed!

    Thanks for your feedback exratione. I do hope that the module will be approved at some point in the not too distant future. It would really be great to let people start using it for real, and to get going with further development of the module.

    sbrattla’s picture

    Issue summary: View changes

    Reviewed module.

    sbrattla’s picture

    Issue summary: View changes

    Updated project description

    sbrattla’s picture

    Issue summary: View changes

    Updated description

    sbrattla’s picture

    Issue summary: View changes

    Updated description.

    sbrattla’s picture

    Issue tags: +PAreview: review bonus

    Carried out a few reviews and commented on other modules. Adding the 'PAReview: review bonus' tag.

    exratione’s picture

    Status: Needs review » Reviewed & tested by the community

    Setting to BRTC based on my review and earlier reviewers' work.

    klausi’s picture

    Status: Reviewed & tested by the community » Needs work
    Issue tags: -PAreview: review bonus
    StatusFileSize
    new6.31 KB

    Review of the 7.x-1.x branch:

    This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.

    manual review:

    • "7.x-1.0-alpha1" follows the git tag name pattern and should not be a branch. Remove that branch.
    • "'#default_value' => check_plain($path),": no need to run check_plain() on #default_value, the Form API will sanitize that for you. Double escaping is bad, please read http://drupal.org/node/28984 again.
    • swiftmailer_menu(): I think the description of the last menu item is wrong.
    • "DEFINE('SWIFTMAILER_ADMINISTER', 'swiftmailer_administer');": "DEFINE" should be "define" (all lower case).
    • "module_load_include('inc', 'swiftmailer', '/includes/helpers/utilities');": Are you sure you need to globally load that file on every single page request? Include it when you actually need it. Also, no need to use module_load_inlcude as you are including files from your own module which you already know where they are. Use something like require_once dirname(__FILE__) . '/mymodule.inc';.
    • "watchdog('swiftmailer', 'An attempt to send an e-mail message failed: !exception_message'": the exception message needs to be properly sanitized with an "@" placeholder.
    • swiftmailer_get_random(): why do you need that function? for $length = 10 you could just call rand(0, 9999999999), right?
    • swiftmailer_admin_default_page(): if you just want to display a form you can use drupal_get_form() as page callback directly in hook_menu() and remove that function.
    • swiftmailer_admin_default_form_submit(): you don't need that function if you use system_settings_form() in swiftmailer_admin_default_form() and rename the form key for the library to the variable name.

    Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

    sbrattla’s picture

    Thank you for your review klausi.

    1. Line endings in 'swiftmailer.info' should now be unix style.
    2. Corrected the things outlined in your attachments to the best of my efforts.
    3. Deleted the '7.x-1.0-alpha1' branch.
    4. Removed 'check_plain' from '#default_value' (swiftmailer_admin_default.inc)
    5. Corrected description in swiftmailer_menu() (swiftmailer.module)
    6. Replaced 'DEFINE' with 'define' (swiftmailer.module)
    7. Removed 'module_load_include' so that it is not loaded globally. Inserted 'module_load_include' in contexts where required. I'm using 'module_load_include' and not 'require_once' as I like to stick to the Drupal API. (swiftmailer.module)
    8. Sanitized watchdog() (SWIFTMailSystem.inc)
    9. Completely removed swiftmailer_get_random() (utilities.inc)
    10. I like having a page function which then renders a form. This way, If I for some reason need to add elements to the page or do something else with that page it is an easy fix.
    11. Same as #10.

    Thank you for your review. A lot of valuable feedback, and I believe I got it all sorted.

    sbrattla’s picture

    Status: Needs work » Needs review
    sbrattla’s picture

    Would be really cool if the module didn't have to celebrate it's first birthday in the sandbox :-)

    sbrattla’s picture

    Issue summary: View changes

    Updated description.

    sbrattla’s picture

    Issue summary: View changes

    Added review note.

    sbrattla’s picture

    Issue summary: View changes

    Added review note.

    sbrattla’s picture

    Issue tags: +PAreview: review bonus

    Carried out review of three modules.

    alexiswatson’s picture

    Status: Needs work » Needs review

    Everything passes Coder review. Manual review:

    • swiftmailer.info:4 - Remove "mail" package per http://groups.drupal.org/node/97054
    • swiftmailer.install:13 - This module appears to clobber all other mail systems in hook_install(). http://drupal.org/node/900794#comment-4160574 explains that this may not be such a great idea if that array is already populated. http://drupal.org/project/mailsystem provides an API that you might consider using for doing this more cleanly.
    • includes/classes/SWITFMailSystem.inc:267 - New control structures should be on a new line.
    • includes/helpers/conversion.inc:7 - define() should be lowercase.

    Additional suggestions:

    • swiftmailer.module:66 - The constant here is non-standard. I'd stick to the string literals for permissions.
    • swiftmailer.module:27 - Same thing here - I'd stick with the string literals for variable_g|set keys. The pattern isn't used elsewhere, and not much is gained by making them constants.
    • includes/pages/swiftmailer_admin_default.inc:48 - The constant SWIFTMAILER_VARIABLE_PATH_DEFAULT forces the dev to look in another file for the default path. Should probably be a string literal.
    • includes/helpers/conversion.inc:81 - Could be shortened to return preg_match(…);
    • includes/helpers/conversion.inc:328 - Could be shortened to return preg_match(…);

    EDIT: Split my review into definite issues versus stylistic/functional suggestions. Hope this helps!

    alexiswatson’s picture

    Status: Needs review » Needs work
    sbrattla’s picture

    Status: Needs review » Needs work

    @davidwatson : thanks for your replies. A few quick lines in reply to your comments:

    1. I've had a look at the package names, and decided to go with 'Other'.
    2. I'll look into the mailsystem module. Absolutely a good idea to integrate with this module.
    3. Not quite sure what you mean about this one :

    includes/classes/SWITFMailSystem.inc:267 - New control structures should be on a new line.

    4. Changed DEFINE to define.
    5. With regards to the constants : I've created a few modules earlier which has grown rather large, and at some point I've always had the need to get a little more overview of the variables that have been in use. That is where the use of constants comes in. I do understand your point where you say that it is unecessary to use constants for variable names, and I could certainly just go with the actual variable names. However, I think the constants for default variable values add value as I might be using the variables several places. When doing that, I would still have to look up the first usage of the variable to see what the default value was, and that would require me to open another file. However, as it is right now, I know that i just need to go to the main module file to find the default value. I guess it goes under "style of coding". I'd be happy to change it if that is what it takes to get the module approved. However, I like having it that way.
    6. With regards to the preg_match issues: preg_match returns 0 or 1, and even though a simple evaluation of 0 and 1 vs. false and true would return the same result, i still like the idea of returning the correct types. That is, if, for some reason someone would do a value and type comparison ($matched === TRUE) then the method's return value would still evaluate correctly. Again, i guess it is a style of coding and I could certainly shorten it to

    if preg_match(...) ? TRUE : FALSE;

    However, keeping it the other way keeps the method in style with the other methods in that file (which sort of is in the same "familiy" of functions) and that is why I've done it that way.

    Again, thank you very much for your feedback. It would be great if you have the chance to write a little more in detail about #3. I'll absolutely look into #2 as soon as possible.

    alexiswatson’s picture

    Hi sbrattla!

    1. No need to define it explicitly; it's the default package where none is defined. :]
    2. I'm curious to see the results!
    3. Apologies for the ambiguity; see http://drupal.org/coding-standards#controlstruct. Rather than:

    if (condition1 || condition2) {
      // foo
    } elseif (condition3 && condition4) {
      // bar
    } else {
      // baz
    }

    The standard would be:

    if (condition1 || condition2) {
      // foo
    } 
    elseif (condition3 && condition4) {
      // bar
    } 
    else {
      // baz
    }

    with each component of the control structure (if, elseif, else) starting on a new line. The same applies for try-catch and the like.

    4. Fantastic.

    I should clarify again that the remainder were merely suggestions, and would not necessarily block your application from passing review, but I'd happily weigh in below:

    5. Regarding the use of constants, many of them I completely understand and agree with, though I've never seen them used this way in variable_s|get and the like. It is a minor matter of style, though if you prefer to keep them, I for one don't see why it should block the application.
    6. I see your point regarding return types, and agree that

    if preg_match(...) ? TRUE : FALSE;
    

    may be stronger. Generally speaking, it is best to use the minimal amount of code to achieve a task, provided it is still readable, performant and self-documenting, which is why I recommended it. Again, however, leaving it as is would not block your application from moving on to the next step in the process.

    EDIT: I would say, however, the configuration setting being used as the value in that variable_set should still be a string, as it is a configuration value versus a magic constant. While I'm still not sure what the value is of having constants that are identical names to keys in the variable table, perhaps someone else can speak to best practice here.

    Happy to help!

    pillarsdotnet’s picture

    if preg_match(...) ? TRUE : FALSE;
    

    As the above is not valid PHP code, presumably you mean one of the following:

    • if (preg_match(...) ? TRUE : FALSE) {
       ...
      
    • return (preg_match(...) ? TRUE : FALSE);
      
    • if (preg_match(...)) {
        return TRUE;
      }
      return FALSE;
      
    sbrattla’s picture

    Absolutely, you're right. It turned out as an odd mix between pseudo code and real code :-D

    sbrattla’s picture

    Status: Needs review » Needs work

    Hi,

    1. Alright. I see that the 'mailsystem' module uses the 'Mail' package, so I've decided to go with that as I'm aiming to integrate with that module.

    2. I've successfully integrated the module with the 'mailsystem' module. At first, the mailsystem module crashed my entire site due to a known bug. However, there's a patch available for it and it worked well. I'm a little concerned about integrating with a module that brings entire sites down though. The patch seems to be ready, but just has not been commited yet (even though it was created a month ago)

    3. Fixed! Thanks for pointing it out.

    I appreciate your suggestions, and I absolutely think your points are valid. Speaking for myself, then only reason why i define variables is to keep an overview of which variables I'm using. It's like an index. However, I could just as well be using the hook_uninstall() for this purpose, as all variables in use should be cleaned up here. I do like the way I'm organising default
    variable values though, so I think i'll stick to that one.

    I've commited the changes if you like to see them :-)

    sbrattla’s picture

    Status: Needs work » Needs review
    klausi’s picture

    Status: Needs work » Reviewed & tested by the community
    Issue tags: -PAreview: review bonus
    StatusFileSize
    new5.78 KB

    Thanks for your reviews, just make sure that you pick applications that did not get a review in a long time. When finishing your review comment also set the issue status either to "needs work" (you found some problems with the project) or "reviewed & tested by the community" (you found no flaws).

    Review of the 7.x-1.x branch:

    This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.

    manual review:

    1. swiftmailer_admin_default_form(): no need to use module_load_inlcude as you are including files from your own module which you already know where they are. Use something like require_once dirname(__FILE__) . '/mymodule.inc';.
    2. Also elsewhere.
    3. "'#default_value' => check_plain($user->mail),": do not use check_plain() on #default_value form API keys, the form API will automatically sanitize that for you. See http://drupal.org/node/28984 Also elsewhere in your code.

    Although you should definitively fix those issues I think this is RTBC. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

    alexiswatson’s picture

    EDIT: Miscommunication (re: #54, thanks!); please disregard.

    klausi’s picture

    @davidwatson: comment #52 was intended for sbrattla.

    sbrattla’s picture

    @klausi : thanks for your feedback, and for setting the status to RTBC. In reply to the things you outlined :

    1. I've replaced module_load_include with require_once.
    2. Replaced all occurences of module_load_include which could be replaced by require_once.
    3. Removed check_plain from #default_value where found.

    I've also corrected the things outlined in the automatic review.

    @davidwatson in #47 : i've replaced the use of variable constants with actual variable names. That is, places where I before would write :

    $path = variable_get(SWIFTMAILER_VARIABLE_PATH, SWIFTMAILER_VARIABLE_PATH_DEFAULT);
    

    will now be

    $path = variable_get('swiftmailer_path', SWIFTMAILER_VARIABLE_PATH_DEFAULT);
    

    I've kept the default values as constants, as I would like to have an easy way to set defaults.

    Again, thanks for your feedback!

    sbrattla’s picture

    Added a feature which might be good since I've now integrated the module against the mailsystem module.

    The mailsystem module allows Drupal to be configured in a way so that e-mails are formatted with one system and sent with another. It does not make sense to require the user to choose which content type Swift Mailer should apply to all e-mails, as this may vary depending on the setup.

    I've thus added an option called 'Respect provided e-mail format' which, if checked, will respect the e-mail format given in the e-mail.

    sreynen’s picture

    Status: Reviewed & tested by the community » Fixed

    Hi sbrattla,

    Thanks for your contribution and welcome to the community of project contributors on drupal.org.

    I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects, at your discretion.

    Now that you've experienced the full review process, please consider reviewing other projects that are still awaiting review. Anyone can help with reviews, following the guidelines.

    sbrattla’s picture

    Hi sreynen!

    Thanks!! This is great! I'm looking forward to be able to publish the project "for real" and develop it further!

    Everyone; thanks a lot for your feedback and reviews!

    Status: Fixed » Closed (fixed)

    Automatically closed -- issue fixed for 2 weeks with no activity.

    Anonymous’s picture

    Issue summary: View changes

    Added review note.