-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tomyeh improvements #170
Open
close2
wants to merge
5
commits into
master
Choose a base branch
from
tomyeh_improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tomyeh improvements #170
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d2f1c1
fix: don't allow `null` ContentText
close2 e55de0e
Manually merge tomyeh/mailer custom3 branch
close2 cb388be
Merge branch 'fix_stream_type' into tomyeh_improvements
close2 97e0cf6
intermediate commit.
close2 1bfa369
feat: v5.0.0! bug fixes and lib update
close2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
# mailer | ||
|
||
|
||
**mailer** is an easy to use library for composing and sending emails in Dart. | ||
|
||
Mailer supports file attachments and HTML emails. | ||
|
||
|
||
## mailer2 and mailer3 | ||
|
||
`mailer2` and `mailer3` on pub.dart are forks of this project. | ||
|
||
`mailer` was not well maintained and `mailer2` and `mailer3` had some important fixes. | ||
|
||
Currently `mailer` should include all known bug-fixes and AFAIK there is | ||
no reason to use `mailer2` or `mailer3`. | ||
|
||
|
||
## Dart2 support | ||
|
||
Support for dart2 has been added in version ^1.2.0 | ||
|
||
Version ^2.0.0 is a rewrite (it too supports dart1.x and dart2). | ||
|
||
Even though the API for ^2.0.0 has slightly changed, *most* programs will probably | ||
continue to work with deprecation warnings. | ||
|
||
## SMTP definitions | ||
|
||
Mailer provides configurations for a few common SMTP servers. | ||
|
@@ -36,7 +15,8 @@ Please create merge requests for missing configurations. | |
* Export the newly created SMTP server in `lib/smtp_server.dart` | ||
* Create a pull request. | ||
|
||
In a lot of cases you will find a configuration in [legacy.dart](https://github.com/kaisellgren/mailer/blob/v2/lib/legacy.dart) | ||
In a lot of cases you will find a configuration | ||
in [legacy.dart](https://github.com/kaisellgren/mailer/blob/v2/lib/legacy.dart) | ||
|
||
## Features | ||
|
||
|
@@ -53,8 +33,8 @@ In a lot of cases you will find a configuration in [legacy.dart](https://github. | |
* Correct encoding of non ASCII mail addresses. | ||
* Reintegrate address validation from version 1.* | ||
* Improve Header types. (see [ir_header.dart](lib/src/smtp/internal_representation/ir_header.dart)) | ||
We should choose the correct header based on the header name. | ||
Known headers (`list-unsubscribe`,...) should have their own subclass. | ||
We should choose the correct header based on the header name. | ||
Known headers (`list-unsubscribe`,...) should have their own subclass. | ||
* Improve documentation. | ||
|
||
## Examples | ||
|
@@ -76,7 +56,7 @@ main() async { | |
// final smtpServer = SmtpServer('smtp.domain.com'); | ||
// See the named arguments of SmtpServer for further configuration | ||
// options. | ||
|
||
// Create our message. | ||
final message = Message() | ||
..from = Address(username, 'Your name') | ||
|
@@ -97,8 +77,8 @@ main() async { | |
} | ||
} | ||
// DONE | ||
|
||
|
||
// Let's send another message using a slightly different syntax: | ||
// | ||
// Addresses without a name part can be set directly. | ||
|
@@ -109,32 +89,37 @@ main() async { | |
// `new Address('[email protected]')` is equivalent to | ||
// adding the mail address as `String`. | ||
final equivalentMessage = Message() | ||
..from = Address(username, 'Your name') | ||
..recipients.add(Address('[email protected]')) | ||
..ccRecipients.addAll([Address('[email protected]'), '[email protected]']) | ||
..bccRecipients.add('[email protected]') | ||
..subject = 'Test Dart Mailer library :: 😀 :: ${DateTime.now()}' | ||
..text = 'This is the plain text.\nThis is line 2 of the text part.' | ||
..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>"; | ||
|
||
..from = Address(username, 'Your name 😀') | ||
..recipients.add(Address('[email protected]')) | ||
..ccRecipients.addAll([Address('[email protected]'), '[email protected]']) | ||
..bccRecipients.add('[email protected]') | ||
..subject = 'Test Dart Mailer library :: 😀 :: ${DateTime.now()}' | ||
..text = 'This is the plain text.\nThis is line 2 of the text part.' | ||
..html = '<h1>Test</h1>\n<p>Hey! Here is some HTML content</p><img src="cid:[email protected]"/>' | ||
..attachments = [ | ||
FileAttachment(File('exploits_of_a_mom.png')) | ||
..location = Location.inline | ||
..cid = '<[email protected]>' | ||
]; | ||
|
||
final sendReport2 = await send(equivalentMessage, smtpServer); | ||
|
||
// Sending multiple messages with the same connection | ||
// | ||
// Create a smtp client that will persist the connection | ||
var connection = PersistentConnection(smtpServer); | ||
|
||
// Send the first message | ||
await connection.send(message); | ||
|
||
// send the equivalent message | ||
await connection.send(equivalentMessage); | ||
|
||
// close the connection | ||
await connection.close(); | ||
|
||
} | ||
``` | ||
|
||
## License | ||
|
||
This library is licensed under MIT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
class Address { | ||
String? name; | ||
String? mailAddress; | ||
final String? name; | ||
final String mailAddress; | ||
|
||
Address([this.mailAddress, this.name]); | ||
const Address(this.mailAddress, [this.name]); | ||
|
||
/// The name used to output to SMTP server. | ||
/// Implementation can override it to pre-process the name before sending. | ||
/// For example, providing a default name for certain address, or quoting it. | ||
String? get sanitizedName => name; | ||
/// The address used to output to SMTP server. | ||
/// Implementation can override it to pre-process the address before sending | ||
String get sanitizedAddress => mailAddress; | ||
|
||
/// Generates an address that must conform to RFC 5322. | ||
/// For example, `name <[email protected]>`, `<[email protected]>` | ||
/// and `foo.domain.com`. | ||
@override | ||
String toString() { | ||
var fromName = name ?? ''; | ||
// ToDo base64 fromName (add _IRMetaInformation as argument) | ||
return '$fromName <$mailAddress>'; | ||
} | ||
String toString() => "${name ?? ''} <$mailAddress>"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,15 @@ enum Location { | |
/// Represents a single email attachment. | ||
/// | ||
/// You may specify a [File], a [Stream] or just a [String] of [data]. | ||
/// [cid] allows you to specify the content id. | ||
/// [cid] allows you to specify the content id for html inlining. | ||
/// | ||
/// When [location] is set to [Location.inline] The attachment (usually image) | ||
/// can be referenced using: | ||
/// `cid:yourCid`. For instance: `<img src="cid:yourCid" />` | ||
/// | ||
/// [cid] must contain an `@` and be inside `<` and `>`. | ||
/// The cid: `<[email protected]>` can then be referenced inside your html as: | ||
/// `<img src="cid:[email protected]">` | ||
abstract class Attachment { | ||
String? cid; | ||
Location location = Location.attachment; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,12 +41,14 @@ abstract class _IRContentPart extends _IRContent { | |
late Iterable<_IRContent> _content; | ||
|
||
List<int> _boundaryStart(String boundary) => to8('--$boundary$eol'); | ||
|
||
List<int> _boundaryEnd(String boundary) => to8('--$boundary--$eol'); | ||
|
||
// We don't want to expose the number of sent emails. | ||
// Only use the counter, if milliseconds hasn't changed. | ||
static int _counter = 0; | ||
static int? _prevTimestamp; | ||
|
||
static String _buildBoundary() { | ||
var now = DateTime.now().millisecondsSinceEpoch; | ||
if (now != _prevTimestamp) _counter = 0; | ||
|
@@ -84,7 +86,7 @@ Iterable<T> _follow<T>(T t, Iterable<T> ts) sync* { | |
|
||
class _IRContentPartMixed extends _IRContentPart { | ||
_IRContentPartMixed(Message message, Iterable<_IRHeader> header) { | ||
var attachments = message.attachments ; | ||
var attachments = message.attachments; | ||
var attached = attachments.where((a) => a.location == Location.attachment); | ||
|
||
_active = attached.isNotEmpty; | ||
|
@@ -155,7 +157,7 @@ class _IRContentAttachment extends _IRContent { | |
_header.add(_IRHeaderText('content-transfer-encoding', 'base64')); | ||
|
||
if ((_attachment.cid ?? '').isNotEmpty) { | ||
_header.add(_IRHeaderText('content-id', _attachment.cid)); | ||
_header.add(_IRHeaderText('content-id', _attachment.cid!)); | ||
} | ||
|
||
var fnSuffix = ''; | ||
|
@@ -173,7 +175,7 @@ class _IRContentAttachment extends _IRContent { | |
enum _IRTextType { plain, html } | ||
|
||
class _IRContentText extends _IRContent { | ||
String? _text; | ||
String _text = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should fix the bug mentioned in #167 |
||
|
||
_IRContentText( | ||
String? text, _IRTextType textType, Iterable<_IRHeader> header) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we always require an address?