Permalink
Browse files

first steps to send .mobi via mail

  • Loading branch information...
1 parent d6d56da commit e56547c38cd1ca4198b90f548ac4fae668511913 @reneeb committed Jan 6, 2013
Showing with 86 additions and 3 deletions.
  1. +2 −0 dist.ini
  2. +9 −0 pod_book/config.yml
  3. +2 −0 pod_book/lib/PodBook.pm
  4. +26 −0 pod_book/lib/PodBook/CpanSearch.pm
  5. +47 −3 pod_book/templates/cpan_search/form.html.ep
View
@@ -27,6 +27,8 @@ File::Temp = 0.22
MetaCPAN::API = 0
Mojolicious = 0
Mojolicious::Plugin::YamlConfig = 0
+Mojolicious::Plugin::CHI = 0
+Mojolicious::Plugin::Mail = 0
Regexp::Common = 0
YAML::Tiny = 0
View
@@ -7,6 +7,15 @@ caching:
seconds: 864000
name: cpan2ebook_webservice
name_perltuts: PerltutsCom
+mail:
+ how: smtp
+ howargs:
+ - smtp.server.tld
+ - AuthUser
+ - smtpuser
+ - AuthPass
+ - smtppass
+ from: from@address.tld
userblock_seconds: 2
tmp_dir: /home/ebook/tmp
reverse_proxy: 1
@@ -29,6 +29,8 @@ sub startup {
$ENV{MOJO_REVERSE_PROXY} = 1;
}
+ $self->plugin( 'Mail' => $config->{mail} );
+
# set log level
$self->app->log(
Mojo::Log->new(
@@ -312,6 +312,32 @@ sub debug_epublisher {
sub send_download_to_client {
my ($self, $data, $name) = @_;
+ # send mobi file to mail address
+ my $type = lc $self->param('target');
+ my $mobi_send = $self->param( 'mobi_send' ) || $self->cookie( 'mail' );
+
+ if ( $type eq 'mobi' && $mobi_send ) {
+ my ($mail,$save) = split /\|\|/, $mobi_send;
+
+ # save mail address in cookie if requested
+ if ( $save && $save eq 'yes' && $mail ) {
+ $self->cookie( mail => $mail );
+ }
+
+ if ( $mail ) {
+ $self->app->log->info( "Send $name via mail" );
+ $self->mail(
+ mail => {
+ },
+ attach => [
+ ],
+ );
+ $self->stash( mobi_sent => 1 );
+ $self->render;
+ return;
+ }
+ }
+
$self->app->log->info("Sending for download: '$name'");
my $headers = Mojo::Headers->new();
@@ -1,14 +1,16 @@
% layout 'main', title => 'perlybook', appversion => $appversion;
<h1>PerlyBook</h1>
-<form action="/" method="post">
+<form action="/" method="post" id="perlybook">
<div class="ui-widget">
<input id="source" name="source" />
</div>
<br />
<small><input type="checkbox" name="book_selection" value="distribution" checked> fetch complete release</small>
<br />
- <button name="target" type="submit" value="epub">EPUB</button>
- <button name="target" type="submit" value="mobi">MOBI</button>
+ <button name="target" type="submit" value="epub" id="epub_btn">EPUB</button>
+ <button name="target" type="submit" value="mobi" id="mobi_btn">MOBI</button>
+
+ <input type="hidden" name="mobi_send" id="mobi_send" />
<br />
</form>
<div id="msg">
@@ -17,3 +19,45 @@
</p>
<%== $optional_message %>
</div>
+<div id="dialog" title="Send .mobi to Kindle">
+ <label for="mail">Send to:</label>
+ <input type="text" id="mail" name="mail" />
+
+ <br />
+
+ <label for="save">Save address in cookie:</label>
+ <select id="save" name="save">
+ <option value="never">never</option>
+ <option value="yes">yes</option>
+ <option value="not_now">not now</option>
+ </select>
+</div>
+
+<script type="text/javascript">
+ $(document).ready( function() {
+ $('#mobi_btn').click( function() {
+ $('#dialog').dialog( 'open' );
+ return false;
+ });
+
+ $('#dialog').dialog({
+ autoOpen: false,
+ height: 250,
+ width: 400,
+ modal: true,
+ buttons: {
+ Ok: function() {
+ $('#mobi_send').val(
+ $('#mail').val() + '||' + $('#save').val()
+ );
+ $(this).dialog( 'close' );
+ $('#perlybook').submit();
+ },
+ Cancel: function() {
+ $(this).dialog( 'close' );
+ $('#perlybook').submit();
+ },
+ }
+ });
+ });
+</script>

0 comments on commit e56547c

Please sign in to comment.