<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/test/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pfb</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/test/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pfb"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/Special:Contributions/Pfb"/>
	<updated>2026-07-28T04:20:12Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Email_processing&amp;diff=26176</id>
		<title>Email processing</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Email_processing&amp;diff=26176"/>
		<updated>2007-08-21T22:20:21Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Experimental email processing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Features ==&lt;br /&gt;
&lt;br /&gt;
Moodle now makes better use of the SMTP protocol and email in general. Most of the benefits result from using a technique known as Variable Envelope Return Path (VERP).&lt;br /&gt;
&lt;br /&gt;
* Works on most modern MTAs (at least on Unix systems).&lt;br /&gt;
* All processing of bounces and replies is secured using HMAC-MD5-8.&lt;br /&gt;
* Bounces are handled correctly and increase a &amp;quot;bad email&amp;quot; score for the user.&lt;br /&gt;
* noreply@host address is now on Reply-to field, avoiding accidental pollution of users address books.&lt;br /&gt;
* noreply@host has an autorresponder&lt;br /&gt;
* Makes it easy for modules to send emails with a signed VERP reply-to.&lt;br /&gt;
* Handles receving of VERP replies: Validates the HMAC-MD5-8 signature and Dispatches the encoded request data to the relevant module&lt;br /&gt;
&lt;br /&gt;
== Moodle configuration ==&lt;br /&gt;
&lt;br /&gt;
Edit config.php to enable bounce handling, and setup Moodle to match your MTA configuration. Here&#039;s how. Uncomment these lines in config.php (if you cannot find them, copy them from config-dist.php):&lt;br /&gt;
&lt;br /&gt;
  // once handlebounces is true, we will be using VERP for the return address of every sent email&lt;br /&gt;
  $CFG-&amp;gt;handlebounces = true;&lt;br /&gt;
  // minimum bounces allowed per user&lt;br /&gt;
  $CFG-&amp;gt;minbounces = 10;&lt;br /&gt;
  // ratio of bad emails to sent emails&lt;br /&gt;
  // if we get more than 20% bounces &lt;br /&gt;
  // for a given user, his/her email is marked bad&lt;br /&gt;
  $CFG-&amp;gt;bounceratio = .20;&lt;br /&gt;
&lt;br /&gt;
Edit the $CFG-&amp;gt;maildomain line and one of the $CFG-&amp;gt;mailprefix lines (the one that matches your MTA).&lt;br /&gt;
&lt;br /&gt;
Make sure your server has a command-line PHP interpreter, and that it is able to connect to mysql (or postgres if relevant). If you are able to run cron.php from the commandline or from crontab, this means PHP is ok.&lt;br /&gt;
&lt;br /&gt;
Edit the process_email.php script to point to the location of your php binary. It will usually be &#039;&#039;/usr/bin/php&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure &#039;&#039;process_email.php&#039;&#039; is executable by running &amp;quot;chmod ugo+rx process_email.php&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Setup under Postfix ==&lt;br /&gt;
&lt;br /&gt;
Add a line to your aliases file. The line should list a 3-letter prefix, to which we&#039;ll add a &#039;|&#039;, and the path of the script. For example for a prefix of &#039;mdl&#039; and moodle installed under /var/www/moodle we have in aliases:&lt;br /&gt;
&lt;br /&gt;
    mdl:     |/var/www/moodle/admin/process_email.php&lt;br /&gt;
    noreply: |/var/www/moodle/admin/process_email.php&lt;br /&gt;
&lt;br /&gt;
If you are using virtualdomains, consult your server administrator for the correct configuration. It probably involves editing transports and mapping your address to a &amp;quot;pipe&amp;quot; transport.&lt;br /&gt;
&lt;br /&gt;
== Setup under Qmail ==&lt;br /&gt;
&lt;br /&gt;
Depending on your setup, your aliases will be controlled by one or more of&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;/etc/aliases&#039;&#039;&lt;br /&gt;
* &#039;&#039;/var/qmail/alias/.qmail-PREFIX&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you edit /etc/aliases add a line like this (for a prefix of &#039;mdl&#039;):&lt;br /&gt;
&lt;br /&gt;
    mdl:     |/var/www/moodle/admin/process_email.php&lt;br /&gt;
    noreply: |/var/www/moodle/admin/process_email.php&lt;br /&gt;
&lt;br /&gt;
If you create /var/qmail/alias/.qmail-PREFIX, just do&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;|/var/www/moodle/admin/process_email.php&amp;quot; &amp;gt; /var/qmail/alias/.qmail-mdl&lt;br /&gt;
  echo &amp;quot;|/var/www/moodle/admin/process_email.php&amp;quot; &amp;gt; /var/qmail/alias/.qmail-noreply&lt;br /&gt;
&lt;br /&gt;
To this three letter prefix, we will add a &#039;-&#039; when sending and receiving messages. For more info, check out the manpage for dot-qmail.&lt;br /&gt;
&lt;br /&gt;
== Setup under Exim ==&lt;br /&gt;
&lt;br /&gt;
Open &#039;&#039;/etc/exim/exim.conf&#039;&#039; and add to trusted_users the user Apache and cron.php run as (usually &amp;quot;www-data&amp;quot; or &amp;quot;nobody&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Add a line to your aliases file. The line should list a 3-letter prefix, to which we&#039;ll add a &#039;+&#039;, and the path of the script. For example for a prefix of &#039;mdl&#039; we have in aliases:&lt;br /&gt;
&lt;br /&gt;
    mdl:     |/var/www/moodle/admin/process_email.php&lt;br /&gt;
    noreply: |/var/www/moodle/admin/process_email.php&lt;br /&gt;
&lt;br /&gt;
If you are using virtualdomains, consult your server administrator for the correct configuration. It probably involves editing transports and mapping your address to a &amp;quot;pipe&amp;quot; transport.&lt;br /&gt;
&lt;br /&gt;
More documentation about Exim can be found [http://www.exim.org/docs.html here]. You may have to tell Exim not to lowercase the local-part.&lt;br /&gt;
&lt;br /&gt;
== Developer info ==&lt;br /&gt;
&lt;br /&gt;
Changed functions:&lt;br /&gt;
&lt;br /&gt;
* email_to_user() will set the envelope sender to a special bounce processing address (based on $CFG settings)&lt;br /&gt;
* email_to_user() will accept (and set) a reply-to header, to be generated by the module calling the function.&lt;br /&gt;
* associated string changes/additions&lt;br /&gt;
&lt;br /&gt;
New functions:&lt;br /&gt;
&lt;br /&gt;
* generate_email_processing_address() - ALWAYS use this to generate the reply-to header. reply-to header will look like this: (LIMIT: 64 chars total) prefix - EXACTLY four chars encodeded, packed, moduleid (0 for core) (2 chars) up to 42 chars for the modules to put anything they want it (can contain userid (or, eg for forum, postids to reply to), or anything really. 42 chars is ABSOLUTE LIMIT) 16 char hash (half an md5) of the first part of the address, together with a site &amp;quot;secret&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* moodle_process_email() - any non-module email processing goes here (currently used for processing bounces)&lt;br /&gt;
&lt;br /&gt;
New files:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;admin/process_email.php&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This script needs to be called from your MTA for anything starting with the 3 char prefix described above (and optionally, the noreply address).&lt;br /&gt;
&lt;br /&gt;
How does it work? It will break down and unencode the email address into moduleid and validate the half md5 hash, and call $modname_process_email (if it exists). Arguments to these functions are: $modargs (any part of the email address that isn&#039;t the prefix, modid or the hash) and the contents of the email (read from STDIN).&lt;br /&gt;
&lt;br /&gt;
It doubles up as the noreplyaddress autorresponder if you configure it with that address as well. Replying with a friendly &amp;quot;this is not a real email address&amp;quot; message.&lt;br /&gt;
&lt;br /&gt;
== Module Authors ==&lt;br /&gt;
&lt;br /&gt;
Take a look at new functions moodle_process_email() and generate_email_processing_address() in moodlelib.php for ideas about how to&lt;br /&gt;
&lt;br /&gt;
* encode and unencode the arguments your module needs to do the processing&lt;br /&gt;
* how to deal with multiple &amp;quot;actions&amp;quot; for any given module.&lt;br /&gt;
&lt;br /&gt;
In a nutshell, users can send emails to Moodle using special dynamic addresses. These emails can trigger a call to a module function in the form of modulename_process_email($str, $bodyofemail). The $str part will be up to 42 characters of data generated by Moodle (presumably by your own module), and the $bodyofemailpart is the contents of the email (got by reading STDIN - usually generated by the users MUA).&lt;br /&gt;
&lt;br /&gt;
The 42 characters come from the &amp;quot;local part&amp;quot; of an email address (the part before the @ sign) which can have up to 64 chars. Out of those 64 chars, Moodle uses 22 characters, leaving you with 42 characters to encode data.&lt;br /&gt;
&lt;br /&gt;
What do we do with the 22 chars? Four go to the prefix, which we need to let the MTA know to pass the message to our script. Two go to identify the module ID so we know which module has generated the message (and so we dispatch the request to that module). The remaining 16 are a signature (HMAC-MD5-8) we use to authenticate the message.&lt;br /&gt;
&lt;br /&gt;
Forty-two characters isn&#039;t a lot (although it could be the answer to life, the universe, and everything!) so make sure you use those characters wisely.&lt;br /&gt;
&lt;br /&gt;
The most efficient way to encode database IDs in their full range (so that they can be placed in an email address) we have found is base64_encode(pack(&#039;V&#039;,2147483647)), which returns &amp;quot;/ / / / f w = =&amp;quot;. The two trailing &amp;quot;= =&amp;quot; are redundant and you can remove them (you&#039;ll need to reappend them when retrieving your data). Join your parameters as encoded IDs in positional slots for efficiency.&lt;br /&gt;
&lt;br /&gt;
To retrieve your data, use substr() to separate your parameters, and then unpack(&#039;V&#039;,base64_decode($str)). Note that it&#039;ll return a one-element array.&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
Using &#039;V&#039; reaches 2147483647, half the range of mySQL&#039;s INT. Additionally, &#039;V&#039; behaves like a signed value, rather than an unsigned, so I suspect there&#039;s a bug in PHP&#039;s documentation of pack().&lt;br /&gt;
&lt;br /&gt;
With each ID taking 6-chars (8 chars if we find a way to use the full range of &#039;V&#039;), you have a limited number of parameters. If you need to encode more information, store it in the DB and send emails that point to your stored data. Remember to cleanup this temporary data after a safe period of time.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
Do not try to use variable-width encoding to put IDs, as it&#039;ll work in small installations and break in larger ones.&lt;br /&gt;
&lt;br /&gt;
== Security issues ==&lt;br /&gt;
&lt;br /&gt;
Any code in modulename_process_email() _must_ assume it will see repeat replies and handle them gracefully. The definition of &#039;gracefully&#039; depends on what the code does.&lt;br /&gt;
&lt;br /&gt;
Email servers (MTAs) will sometimes re-transmit a message if they are unsure that the receiving MTA got it -- and sysadmins may sometimes replay a whole email queue if something&#039;s gone wrong. In that case, they email body will be identical, the headers slightly different.&lt;br /&gt;
&lt;br /&gt;
In a different case, the user may &#039;reply&#039; to the message twice. Perhaps in error, perhaps purposefully. What to do depends on the specific scenario.&lt;br /&gt;
&lt;br /&gt;
We /could/ support better protection at the framework level, by keeping track of every reply-to address we send out. We decided against that because (a) the performance impact will be important (b) we want the 1st cut to be lightweight and simple to change in case we need to.&lt;br /&gt;
&lt;br /&gt;
With this the initial implementation, modules should expose functions that handle these &amp;quot;replay&amp;quot; cases correctly. If later we want to expose additional functions, we can add such tracking as an optional thing. It&#039;d be awful to have it across all emails sent from Moodle.&lt;br /&gt;
&lt;br /&gt;
== Experimental email processing, pending merge into 1.9/2.0 ==&lt;br /&gt;
===Module Authors===&lt;br /&gt;
The email interface allows you to let users respond to emails sent via your module and affect change in them. The basic idea is that each email is uniquely identified with an email session that carries with it a simple payload. This payload is stored via database, and cannot be changed by the user. Replies are handled by module code in your lib.php library - modulename_process_email($payload, $body) - which is passed the session payload and the body (with full headers) of the email received, to be parsed as you like. Some utility functions are available as well to help with this.&lt;br /&gt;
&lt;br /&gt;
Here is an outline of the intended use:&lt;br /&gt;
* Before sending an email to a user via the email_to_user() function, the module should check to see if the config variable $CFG-&amp;gt;emailinterface is enabled. (This is off by default)&lt;br /&gt;
* Assuming the email interface is enabled, the function generate_email_verp_address($moduleid, $payload, $userid) should be called to create an &amp;quot;email session&amp;quot;. The payload should include any data you wish to use in your handling routine - such as the id of the user, or what part of the interface he is interacting with. The function will return a string containing the email session id.&lt;br /&gt;
* Call the email_to_user() function as normal, appending the email session id as the 11th parameter. Keep in mind that you will probably also need to change the text or html of the email to point out that the email interface is active.&lt;br /&gt;
* A function contained in the lib.php file of your module, named [modulename]_process_email($payload, $body) should be written. This is the handler function, which is called when an email reply is received. This function can inspect the contents of the payload received, then parse the email body for data. The $body parameter returns the full email, including the headers.&lt;br /&gt;
&lt;br /&gt;
Note that each email can only be replied to once - the email session is destroyed once an email has been received. If you wish to have multiple replies from a user, you will have to create a new session (and new email) every time. The email session table is also regularly pruned, the default settings allow sessions to persist for one month.&lt;br /&gt;
&lt;br /&gt;
The following utility functions are also defined in admin/process_email.php, which can help:&lt;br /&gt;
* get_email_subject($fullemail) - return the subject of an email&lt;br /&gt;
* strip_email_headers($fullemail) - strip all headers off an email&lt;br /&gt;
* email_is_multipart($fullemail) - determine if an email is a multipart message&lt;br /&gt;
* seperate_multipart($multipartmsg) - seperate a multipart email message into an array of parts, each of which has headers and a body.&lt;br /&gt;
* get_multipart_content_type($part) - determine the content-type of a multipart, generally text/plain or text/html.&lt;br /&gt;
* multipart_is_quoted_printable($part) - determine if a email part has been encoded with the quoted-printable encoding - some email clients tend to do this to html.&lt;br /&gt;
* decode_quoted_printable($partdata) - decode a email that has been encoded with quoted-printable encoding - this needs to be run on the data section of a part (strip_email_headers can be used to seperate the headers of a part).&lt;br /&gt;
* strip_email_reply($body, $ishtml, $identifier) - strip all irrelevant lines of an email message based on a unique identifier embedded within the original message. This is used to determine what is user input, and what is irrelevant data the email client has added.&lt;br /&gt;
* strip_email_reply_multi($body, $ishtml, $identifier) - as above, but allowing for multiple sections of possible user input in a single email message.&lt;br /&gt;
&lt;br /&gt;
Examples of use of these functions can be seen in the handler for the forum module. The idea behind the strip reply functions is that the original email will contain a unique identifier, such as a random 10 character string. This is embedded in a line with instructions for the user to write below and above it, e.g:&lt;br /&gt;
  \/ Please put your response here [ABCDEFGHIJ] \/&lt;br /&gt;
  &amp;lt;User Data&amp;gt;&lt;br /&gt;
  /\ Please put your response here [ABCDEFGHIJ] /\&lt;br /&gt;
This is necessary because of the wide differences between webmail and email clients in handling quotes and prefixing dates/times to replied emails. Keep in mind that text emails have an 80-character line width restrictions, which must also include the quote added by the email client, so any line of a text-email with this identifier should be kept to at least 77 characters to avoid wrapping by an email client. This unique identifier can be easily stored in the payload. Multiple input sections are handled similarly - a number is appended to the end of the identifier, e.g. [ABCDEFGHIJ1] to signfiy the first section of input. The strip_email_reply_multi returns an array containing a map from each numbered section it finds to a string containing all data in that section.&lt;br /&gt;
&lt;br /&gt;
===Developer Info===&lt;br /&gt;
The reply-to header is now encoded in base32 instead of base64 to allow for case-insensitive MTA&#039;s. Generate_email_processing_address was left as a backwards-compatibility wrapper, modules should use generate_email_verp_address now instead.&lt;br /&gt;
&lt;br /&gt;
Email sessions have been created to deal with the lack of space avaliable in the header under base32, payloads are stored in a new table mdl_email_sessions, and are identified with a unique base32 key which is embedded in the reply-to header. Each row has a timestamp, and the table is pruned during cleanup cron in admin/cron.php.&lt;br /&gt;
&lt;br /&gt;
Bounce detection is now linked in with the email interface - bounce detection is included in admin/process_email.php. Some new configuration variables have also been created to help configure these changes - $CFG-&amp;gt;emailinterface and $CFG-&amp;gt;emailsessiontime - and both have been added to the server settings admin page.&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=25262</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=25262"/>
		<updated>2007-07-22T06:03:22Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Updated to latest changes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. The following design is proposed:&lt;br /&gt;
&lt;br /&gt;
mdl_email_sessions:&lt;br /&gt;
* id : int(10), key field, auto-inc - required by DML&lt;br /&gt;
* b32key : int(10), unsigned - session number of the email, encoded in a base32 part of the VERP field. An index has to be created on this to allow for fast lookup when an email is received.&lt;br /&gt;
* data : text(medium) - field to store data of any length mapped to this email session. This will probably be either a plain ascii parameter or a serialized object.&lt;br /&gt;
* timestamp : int(10), unsigned - timestamp of the email sent which registered this session. This is to allow &amp;quot;old&amp;quot; sessions to be removed after a defined time interval when they are no longer valid during cron.&lt;br /&gt;
&lt;br /&gt;
An entry is inserted into the session table if either bounce handling or the email interface is enabled. We must ensure our data field is large enough to handle decently sized serialized objects - a medium text field in mysql stores 16 million characters, which is more than enough.&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==VERP structure==&lt;br /&gt;
&lt;br /&gt;
The structure of the VERP field has been changed several times since coding started - here is the latest version:&lt;br /&gt;
* 4 characters: prefix for MTA (&amp;quot;mdl+&amp;quot;, etc.)&lt;br /&gt;
* 2 characters: encoded (base32 + pack(&#039;C&#039;)) module id to determine which processing function to call - module id 0 stands for Moodle &#039;core&#039;.&lt;br /&gt;
* 16 characters: encoded (base32 + pack(&#039;C&#039;)) user id - this is only used for bounce processing, and is not passed upwards to handling functions. Any user identification is expected to be stored within the session data field.&lt;br /&gt;
* 16 characters: encoded (base32 + pack(&#039;C&#039;)) session id - this is used to identify the session row in mdl_email_sessions, and matches the b32key.&lt;br /&gt;
* 26 characters: hash validating and securing the VERP data. HMAC-MD5-26 is used for this.&lt;br /&gt;
&lt;br /&gt;
==Security concerns==&lt;br /&gt;
&lt;br /&gt;
Rather than using the auto-incremental id field as the session key, which would reduce the amount of data we need to store per email in the session table, a randomly generated number is used instead. Because identity should be stored within the session data, it would be extremely unlikely that even if the site identifier were known and a collision computed that a person would know another session key that should be using. The identity of the user id field in the VERP address is used only for bounce detection purposes, but this requires a session key to have been generated beforehand (and MD5 to match) to prevent denial of service attacks to force a users email address to go over their bounce-quota.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailed replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major issues==&lt;br /&gt;
===Handling bounce messages (Delivery Status Notifications)===&lt;br /&gt;
The framework is able to distinguish between messages sent by a user in response to an email, or automated DSN / &amp;quot;bounce&amp;quot; messages sent by a MTA. This is done via checking for a null return path, or existence of specific content-types which are identified as DSN specific by RFC 1894. Once a message has been identified as such, it is simply discarded - the session entry is not removed, as it is possible for these messages to be generated if an email is only temporarily unreachable.&lt;br /&gt;
===Pruning the session table===&lt;br /&gt;
Each session entry has an associated timestamp to identify when it was created - this can be used to prune the table of all entries before a certain period. A config variable - $CFG-&amp;gt;mailsessiontime - stores the number of hours email sessions persist (defaulting to 1 month). A cron function (cleanup function) written in admin/cron.php is used to prune the session table.&lt;br /&gt;
===Handling HTML===&lt;br /&gt;
Some email clients send HTML encodings of the actual email message - should we parse these or simply provided functions to allow module code to parse them? Should we also handle MIME attachments like this?&lt;br /&gt;
===Backwards compatibility===&lt;br /&gt;
Existing code already is in place that implements a email interface (in base64) as well as a email bounce handling facility - this has been retained and new code made available so that existing modules depending on these do not need to be modified.&lt;br /&gt;
===Digest messages for the Forum module===&lt;br /&gt;
Users can choose for messages to be queued up in a single &amp;quot;digest&amp;quot; that is sent to them regularly. A method needs to be chosen to determine which message a reply to this digest is intended for.&lt;br /&gt;
&lt;br /&gt;
==User interface ideas==&lt;br /&gt;
&lt;br /&gt;
* In &amp;quot;digest&amp;quot; style emails, we need to be able to identify which discussion the reply is intended for.&lt;br /&gt;
** HTML formatted emails can have mailto: links which specify a pre-existing body which contains data on which discussion this is intended for.&lt;br /&gt;
** Plain text emails could be handled by requiring the user to insert some separator (&amp;quot;&amp;gt;&amp;gt;1&amp;quot; to refer to message one) before inserting his post.&lt;br /&gt;
** Plain text emails can have some sort of separators between posts, and the reply must be inserted after the correct separator, e.g:&lt;br /&gt;
 (Original email)&lt;br /&gt;
 !Message 1 Separator!&lt;br /&gt;
 Text of message one goes here.&lt;br /&gt;
 !Message 2 Separator!&lt;br /&gt;
 Text of message two goes here.&lt;br /&gt;
&lt;br /&gt;
 (Replied email)&lt;br /&gt;
 &amp;gt; !Message 1 Separator!&lt;br /&gt;
 &amp;gt; Text of message one goes here.&lt;br /&gt;
 User inserts message one reply here if he wants to reply to this specific message.&lt;br /&gt;
 &amp;gt; !Message 2 Separator!&lt;br /&gt;
 &amp;gt; Text of message two goes here.&lt;br /&gt;
* We need to be able to separate the &amp;quot;reply&amp;quot; of the email from the quote and any prefix added by the mail client.&lt;br /&gt;
** HTML could contain specific elements (hr&#039;s) with id tags identifying the current discussion that the user would post between.&lt;br /&gt;
** Plain text email could also emulate the above with a rather more crude &amp;quot;insert reply below this line&amp;quot; approach.&lt;br /&gt;
&lt;br /&gt;
==Timeline and current progress==&lt;br /&gt;
&lt;br /&gt;
July 9th was used as a milestone for completion of the framework and some changes to the Forum module - at this stage, there was a working prototype of the framework and appropriate Forum module code, but many further refinements to the framework could still be made, specifically parsing and utility functions that all modules could use to help separate data in returned email bodies from redundant lines.&lt;br /&gt;
&lt;br /&gt;
Another milestone should be reached by the end of July - a working prototype of the framework and the Forum module processing functions that:&lt;br /&gt;
* Correctly sends emails with appropriate bodies instructing users how to use the interface&lt;br /&gt;
* Recognises responses from single-post mode mails, strips them of erroneous content, and replies to that specific post (including preserving the title of the post if necessary).&lt;br /&gt;
* Recognises responses from digest mode mails including which post the reply is intended from, strips them of erroneous content and replies to that specific post.&lt;br /&gt;
* Some sort of response email for replies to the email interface that encounter errors (such as the email session having expired).&lt;br /&gt;
&#039;&#039;(This will not necessarily be bug-free!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The time until August 20th can be used to test the code, fix/debug it, and hopefully write a few more handlers for other modules - once the framework utility functions are in place, this should be fairly easy!&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24873</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24873"/>
		<updated>2007-07-07T22:19:44Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Added UI ideas.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. The following design is proposed:&lt;br /&gt;
&lt;br /&gt;
mdl_email_sessions:&lt;br /&gt;
* id : char(26), key field - session id of the email, storing the actual base32 encoded session number which matches the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* userid : bigint(10) - user id which this email was sent to. This is used only in bounce processing.&lt;br /&gt;
* data : text - field to store data of any length mapped to this email session. This will probably be either a plain ascii parameter or a serialized object.&lt;br /&gt;
* timestamp : int(10) - timestamp of the email sent which registered this session. This is to allow &amp;quot;old&amp;quot; sessions to be removed after a defined time interval when they are no longer valid during cron.&lt;br /&gt;
&lt;br /&gt;
An entry is inserted into the session table if either bounce handling or the email interface is enabled. We must ensure our data field is large enough to handle decently sized serialized objects. The TEXT type allows for 65535 characters in mysql, we can use medium- or large-text to increase this if neccesary.&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major issues==&lt;br /&gt;
===Handling bounce messages (Delivery Status Notifications)===&lt;br /&gt;
It is neccesary for the framework to be able to distinguish between a message sent by a user in response to an email, or an automated DSN / &amp;quot;bounce&amp;quot; message sent by a MTA. Once a message has been identified as such, it can simply be discarded but must not remove the appropriate session entry, as it is possible for these messages to be generated if an email is only temporarily unreachable.&lt;br /&gt;
===Pruning the session table===&lt;br /&gt;
Each session entry must have an associated timestamp to identify when it was created - this can be used to prune the table of all entries before a certain period. This can be done with a cron function, and suitable defaults must be determined for how long a email session can be &amp;quot;kept&amp;quot;.&lt;br /&gt;
===Handling HTML===&lt;br /&gt;
Some email clients send HTML encodings of the actual email message - should we parse these or simply provided functions to allow module code to parse them? Should we also handle MIME attachments like this?&lt;br /&gt;
===Backwards compatibility===&lt;br /&gt;
Existing code already is in place that implements a email interface (in base64) as well as a email bounce handling facility - hopefully this can be retained and new code made avaliable so that existing modules depending on these do not need to be modified.&lt;br /&gt;
===Digest messages for the Forum module===&lt;br /&gt;
Users can choose for messages to be queued up in a single &amp;quot;digest&amp;quot; that is sent to them regularly. A method needs to be chosen to determine which message a reply to this digest is intended for.&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Addition of new database table into moodle - how is this handled for non-module code?&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
* Create appropriate settings for moodle admin settingpage under server-&amp;gt;email (admin/settings/server.php).&lt;br /&gt;
&lt;br /&gt;
==User interface ideas==&lt;br /&gt;
&lt;br /&gt;
* In &amp;quot;digest&amp;quot; style emails, we need to be able to identify which discussion the reply is intended for.&lt;br /&gt;
** HTML formatted emails can have mailto: links which specify a pre-existing body which contains data on which discussion this is intended for.&lt;br /&gt;
** Plain text emails could be handled by requiring the user to insert some seperator (&amp;quot;&amp;gt;&amp;gt;1&amp;quot; to refer to message one) before inserting his post.&lt;br /&gt;
** Plain text emails can have some sort of seperators between posts, and the reply must be inserted after the correct seperator, e.g:&lt;br /&gt;
 (Original email)&lt;br /&gt;
 !Message 1 Seperator!&lt;br /&gt;
 Text of message one goes here.&lt;br /&gt;
 !Message 2 Seperator!&lt;br /&gt;
 Text of message two goes here.&lt;br /&gt;
&lt;br /&gt;
 (Replied email)&lt;br /&gt;
 &amp;gt; !Message 1 Seperator!&lt;br /&gt;
 &amp;gt; Text of message one goes here.&lt;br /&gt;
 User inserts message one reply here if he wants to reply to this specific message.&lt;br /&gt;
 &amp;gt; !Message 2 Seperator!&lt;br /&gt;
 &amp;gt; Text of message two goes here.&lt;br /&gt;
* We need to be able to seperate the &amp;quot;reply&amp;quot; of the email from the quote and any prefix added by the mail client.&lt;br /&gt;
** HTML could contain specific elements (hr&#039;s) with id tags identifying the current discussion that the user would post between.&lt;br /&gt;
** Plain text email could also emulate the above with a rather more crude &amp;quot;insert reply below this line&amp;quot; approach.&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24738</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24738"/>
		<updated>2007-06-28T21:32:00Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Updated DB table structure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. The following design is proposed:&lt;br /&gt;
&lt;br /&gt;
mdl_email_sessions:&lt;br /&gt;
* id : char(26), key field - session id of the email, storing the actual base32 encoded session number which matches the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* userid : bigint(10) - user id which this email was sent to. This is used only in bounce processing.&lt;br /&gt;
* data : text - field to store data of any length mapped to this email session. This will probably be either a plain ascii parameter or a serialized object.&lt;br /&gt;
* timestamp : int(10) - timestamp of the email sent which registered this session. This is to allow &amp;quot;old&amp;quot; sessions to be removed after a defined time interval when they are no longer valid during cron.&lt;br /&gt;
&lt;br /&gt;
An entry is inserted into the session table if either bounce handling or the email interface is enabled. We must ensure our data field is large enough to handle decently sized serialized objects. The TEXT type allows for 65535 characters in mysql, we can use medium- or large-text to increase this if neccesary.&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major issues==&lt;br /&gt;
===Handling bounce messages (Delivery Status Notifications)===&lt;br /&gt;
It is neccesary for the framework to be able to distinguish between a message sent by a user in response to an email, or an automated DSN / &amp;quot;bounce&amp;quot; message sent by a MTA. Once a message has been identified as such, it can simply be discarded but must not remove the appropriate session entry, as it is possible for these messages to be generated if an email is only temporarily unreachable.&lt;br /&gt;
===Pruning the session table===&lt;br /&gt;
Each session entry must have an associated timestamp to identify when it was created - this can be used to prune the table of all entries before a certain period. This can be done with a cron function, and suitable defaults must be determined for how long a email session can be &amp;quot;kept&amp;quot;.&lt;br /&gt;
===Handling HTML===&lt;br /&gt;
Some email clients send HTML encodings of the actual email message - should we parse these or simply provided functions to allow module code to parse them? Should we also handle MIME attachments like this?&lt;br /&gt;
===Backwards compatibility===&lt;br /&gt;
Existing code already is in place that implements a email interface (in base64) as well as a email bounce handling facility - hopefully this can be retained and new code made avaliable so that existing modules depending on these do not need to be modified.&lt;br /&gt;
===Digest messages for the Forum module===&lt;br /&gt;
Users can choose for messages to be queued up in a single &amp;quot;digest&amp;quot; that is sent to them regularly. A method needs to be chosen to determine which message a reply to this digest is intended for.&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Addition of new database table into moodle - how is this handled for non-module code?&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
* Create appropriate settings for moodle admin settingpage under server-&amp;gt;email (admin/settings/server.php).&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24237</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24237"/>
		<updated>2007-06-16T01:14:01Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Added issues section.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. The following design is proposed:&lt;br /&gt;
&lt;br /&gt;
mdl_email_sessions:&lt;br /&gt;
* id : char(26), key field - session id of the email, storing the actual base32 encoded session number which matches the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* data : text - field to store data of any length mapped to this email session. This will probably be either a plain ascii parameter or a serialized object.&lt;br /&gt;
* timestamp : int(10) - timestamp of the email sent which registered this session. This is to allow &amp;quot;old&amp;quot; sessions to be removed after a defined time interval when they are no longer valid during cron.&lt;br /&gt;
&lt;br /&gt;
We must ensure our data field is large enough to handle decently sized serialized objects. The TEXT type allows for 65535 characters in mysql, we can use medium- or large-text to increase this if neccesary.&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major issues==&lt;br /&gt;
===Handling bounce messages (Delivery Status Notifications)===&lt;br /&gt;
It is neccesary for the framework to be able to distinguish between a message sent by a user in response to an email, or an automated DSN / &amp;quot;bounce&amp;quot; message sent by a MTA. Once a message has been identified as such, it can simply be discarded but must not remove the appropriate session entry, as it is possible for these messages to be generated if an email is only temporarily unreachable.&lt;br /&gt;
===Pruning the session table===&lt;br /&gt;
Each session entry must have an associated timestamp to identify when it was created - this can be used to prune the table of all entries before a certain period. This can be done with a cron function, and suitable defaults must be determined for how long a email session can be &amp;quot;kept&amp;quot;.&lt;br /&gt;
===Handling HTML===&lt;br /&gt;
Some email clients send HTML encodings of the actual email message - should we parse these or simply provided functions to allow module code to parse them? Should we also handle MIME attachments like this?&lt;br /&gt;
===Backwards compatibility===&lt;br /&gt;
Existing code already is in place that implements a email interface (in base64) as well as a email bounce handling facility - hopefully this can be retained and new code made avaliable so that existing modules depending on these do not need to be modified.&lt;br /&gt;
===Digest messages for the Forum module===&lt;br /&gt;
Users can choose for messages to be queued up in a single &amp;quot;digest&amp;quot; that is sent to them regularly. A method needs to be chosen to determine which message a reply to this digest is intended for.&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Addition of new database table into moodle - how is this handled for non-module code?&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
* Create appropriate settings for moodle admin settingpage under server-&amp;gt;email (admin/settings/server.php).&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24073</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=24073"/>
		<updated>2007-06-05T23:55:59Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Updated database structures&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. The following design is proposed:&lt;br /&gt;
&lt;br /&gt;
mdl_email_sessions:&lt;br /&gt;
* id : char(26), key field - session id of the email, storing the actual base32 encoded session number which matches the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* data : text - field to store data of any length mapped to this email session. This will probably be either a plain ascii parameter or a serialized object.&lt;br /&gt;
* timestamp : int(10) - timestamp of the email sent which registered this session. This is to allow &amp;quot;old&amp;quot; sessions to be removed after a defined time interval when they are no longer valid during cron.&lt;br /&gt;
&lt;br /&gt;
We must ensure our data field is large enough to handle decently sized serialized objects. The TEXT type allows for 65535 characters in mysql, we can use medium- or large-text to increase this if neccesary.&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Finalise table structure for the email session handling, if we use it.&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
* Create appropriate settings for moodle admin settingpage under server-&amp;gt;email (admin/settings/server.php).&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23847</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23847"/>
		<updated>2007-05-30T23:56:16Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Added another task&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. A simple sample design is provided below:&lt;br /&gt;
&lt;br /&gt;
mdlEmail_Sessions:&lt;br /&gt;
* Session ID : Key field - this must be big enough to store the maximum values referable by a 42 character base32 encoding. This will match the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* Data : VarChar (or otherwise?) field to store data of any length mapped to this email session. Is there a significant performance hit to using VARCHAR over fixed length CHAR?&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Finalise table structure for the email session handling, if we use it.&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
* Create appropriate settings for moodle admin settingpage under server-&amp;gt;email (admin/settings/server.php).&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23766</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23766"/>
		<updated>2007-05-28T03:08:35Z</updated>

		<summary type="html">&lt;p&gt;Pfb: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. A simple sample design is provided below:&lt;br /&gt;
&lt;br /&gt;
mdlEmail_Sessions:&lt;br /&gt;
* Session ID : Key field - this must be big enough to store the maximum values referable by a 42 character base32 encoding. This will match the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* Data : VarChar (or otherwise?) field to store data of any length mapped to this email session. Is there a significant performance hit to using VARCHAR over fixed length CHAR?&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Finalise table structure for the email session handling, if we use it.&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23765</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23765"/>
		<updated>2007-05-28T03:08:08Z</updated>

		<summary type="html">&lt;p&gt;Pfb: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodle currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space available in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://Moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be necessary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. A simple sample design is provided below:&lt;br /&gt;
&lt;br /&gt;
mdlEmail_Sessions:&lt;br /&gt;
* Session ID : Key field - this must be big enough to store the maximum values referable by a 42 character base32 encoding. This will match the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* Data : VarChar (or otherwise?) field to store data of any length mapped to this email session. Is there a significant performance hit to using VARCHAR over fixed length CHAR?&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email receiving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums receiving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Finalise table structure for the email session handling, if we use it.&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23764</id>
		<title>Student projects/Email interface</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Student_projects/Email_interface&amp;diff=23764"/>
		<updated>2007-05-28T03:04:12Z</updated>

		<summary type="html">&lt;p&gt;Pfb: Initial update&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Programmer:&#039;&#039;&#039; Peter Boswood&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(This is very much still a work in progress, data here may be inaccurate or outdated!)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
Moodle uses email in order to communicate with end users in a variety of manners - for authentication, subscriptions in the Forum module, etc. In some instances, rather than simply ignoring replies from users to these emails, it may be possible to &amp;quot;interpret&amp;quot; them intelligently, carrying out specific actions depending on the Module that sent this email.&lt;br /&gt;
&lt;br /&gt;
==Previous Work==&lt;br /&gt;
&lt;br /&gt;
Moodule currently has functions to allow for dealing with handling email bounces - see [[Email processing]] for more details. This framework allows for the module of a returned email to be uniquely identified, as well as arguments to be passed as part of the email that will be supplied to the module&#039;s handling code.&lt;br /&gt;
&lt;br /&gt;
This framework currently uses base64 encoding in order to encode data used in the return address of the email - this requires case sensitivity, which most MTA&#039;s do not support by default. This will need to be changed to use base32 instead, which significantly decreases the amount of space avaliable in the argument section. This can be mitigated using a &amp;quot;email session cookie table&amp;quot;, as suggested [http://moodle.org/mod/forum/discuss.php?d=24077#114289 here].&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
A database table will be neccesary in order to keep track of the relevant data attached to each email &amp;quot;session&amp;quot;. A simple sample design is provided below:&lt;br /&gt;
&lt;br /&gt;
mdlEmail_Sessions:&lt;br /&gt;
* Session ID : Key field - this must be big enough to store the maximum values referable by a 42 character base32 encoding. This will match the &amp;quot;argument&amp;quot; field of the email&#039;s return address.&lt;br /&gt;
* Data : VarChar (or otherwise?) field to store data of any length mapped to this email session. Is there a significant performance hit to using VARCHAR over fixed length CHAR?&lt;br /&gt;
&lt;br /&gt;
By uniquely identifying each email by a session ID, we can solve the problem mentioned of [[Email processing#Security_issues|handling repeats]] by removing the appropriate row from the table after the handler has run. Replies without an appropriate row could simply be discarded.&lt;br /&gt;
&lt;br /&gt;
==Core functions==&lt;br /&gt;
&lt;br /&gt;
* Framework - non-module code to support framework of the email interface.&lt;br /&gt;
** Functions handling email sending - encoding of the reply-to address header.&lt;br /&gt;
*** Currently implemented as generate_email_process_address in lib/moodlelib.php.&lt;br /&gt;
*** Could be changed to something more specific - e.g. generate_email_session?&lt;br /&gt;
** Functions handling email recieving - decode of the destination (reply-to) header.&lt;br /&gt;
*** Currently implemented as the command line mail parsing script admin/process_email.php.&lt;br /&gt;
*** This currently handles bounces as well as decoding and calling appropriate modules, and may not need to be changed much.&lt;br /&gt;
* Module code - changes to specific modules to actually use the email interface.&lt;br /&gt;
** Forum module&lt;br /&gt;
*** Subscribers to forums recieving &amp;quot;single messages&amp;quot; can have their emailled replies directly added as a reply to that specific post.&lt;br /&gt;
*** Subscribers to forums recieving &amp;quot;digest messages&amp;quot; may need some further interface to specify which post they are replying to, e.g. &amp;quot;3&amp;gt;&amp;gt;Message&amp;quot;.&lt;br /&gt;
** &#039;&#039;(Investigate other modules)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Major tasks==&lt;br /&gt;
&lt;br /&gt;
* Change configuration files (config-dist.php) to include constants for activation of the entire interface - same section as the handling of bounce messages. This should include documentation for them.&lt;br /&gt;
* Finalise table structure for the email session handling, if we use it.&lt;br /&gt;
* Creation / Modification of functions to handle encoding data - including insertion into the session table.&lt;br /&gt;
* Creation / Modification of functions to handle decoding data - from a session table, checking the appropriate hash. This will require us to change admin/process_email.php yet still retain the ability to handle bounces.&lt;br /&gt;
* Creation of a forum_process_email function within the Forum module to allow for action to be taken upon receipt of a message (reply) from a forum subscriber.&lt;br /&gt;
* Modification of the Forum module to pass data about the specific post(s) being sent, possibly by the session table.&lt;br /&gt;
* Look into how to better handle &amp;quot;digest&amp;quot;-style messages?&lt;br /&gt;
&lt;br /&gt;
==Timeline==&lt;br /&gt;
&lt;br /&gt;
July 9th should be a milestone (mid-term evaluations) for the completion of the framework and most (if not all) changes to the Forum module. The period after that (till August 20th) can be used for further changes and refinements to the framework and other modules. Hopefully this can be updated as further details become apparent.&lt;br /&gt;
&lt;br /&gt;
Back to: [[Student projects]]&lt;/div&gt;</summary>
		<author><name>Pfb</name></author>
	</entry>
</feed>