posttdiary-ex.rb : update your tDiary via e-mail


Overview

posttdiary-ex.rb is an program that allows you to update your web diary (run by tDiary) via e-mail. In addition to this function already being provided by the original posttdiary.rb, this "modified" version have been extended in several features, including:

System Requirements

Download

You can get it here:

Installation

posttdiary-ex.rb is not an tDiary plugin, it is basically an independent (and able to be completely independent) script from the tDiary system. However, it is designed to work with tDiary, and can obtain related parameters from your tdiary.conf if you wish.
Example 1: .forward
  "|IFS=' ' && exec ~/bin/posttdiary-ex.rb (options) (url) (username) (password) || exit 75"
Example 2: .qmail
  |preline ~/bin/posttdiary-ex.rb (options) (url) (username) (password)

Testing

When posttdiary-ex.rb meets errors, the mail would be treated as an "deferred" mail and hang around in the mailserver for some days -- this can cause problems. It is strongly recommended that you test your system via the login shell first, before you test it with real e-mails.
1.Prepare an dummy e-mail with an attached image. Name it samplemail.txt.
2.Test printing to STDOUT:

 % ~/bin/posttdiary-ex.rb (options) -d < samplemail.txt

 If it's running fine, new images would be added to the specified directory.
 You'll also see raw text of the mail with some HTML tags.
 Url, username&password for tDiary is not required here.

3.Test updating your diary

 % ~/bin/posttdiary-ex.rb (options) (url) (username) (password) < samplemail.txt

 This should generate new images to the specified directory, and add a new entry to your diary.

4.Test from e-mail and let it writeout to a file

 Edit your .forward (or .qmail, .profmail, etc) to run posttdiary-ex.rb with -b option.

 Example for .forward:

 "|IFS=' ' && exec ~/bin/posttdiary-ex.rb (options) -b /home/(yourname)/result.txt  || exit 75"

 Again, url, username&password for tDiary is not required here.

 Send a e-mail to your corresponding e-mail address. If everything goes well, the text
 of the e-mail would be written in result.txt, and the attached images would be processed.

5.Test from e-mail and update your diary

 Edit your .forward (or .qmail, .profmail, etc) to run posttdiary-ex.rb with url, username/pass.
 If it works -- you're done!
 

Usage

posttdiary-ex.rb: update tDiary via e-mail (v1.52).
usage: ruby posttdiary-ex.rb [options (without -d)]   
       ruby posttdiary-ex.rb [options (with -d)]
arguments:
  url:    update.rb's URL of your diary
  user:   username for your tDiary system
  passwd: password for your tDiary system
          If the To: field is  formatted as "user-passwd@example.com",
          you can omit user and passwd arguments.
options:
  ============ for automatic configuration ==========
  --read-conffile,   -a dirname: read settings from (dirname)/tdiary.conf
          Reads configuration parameters of image_ex plugin as well.
          (The default values of -i, -u, -t, -z, -o, -y, -C can be obtained.)
          Specify the localtion (or fullpathname) of tDiary conf file.
          ex. -a /home/hoge/htdocs/diary/tdiary.conf

  ============ basic options ==============
  --image-path,      -i dirname: directory to store the image(s) in.
  --image-url,       -u URL: URL of the image directory.
          you must specify both -i and -u options
          (unless they are available from tdiary.conf + image_ex plugin)
  --use-subject,     -s: use mail subject as subtitle
          Also inserts attached image(s) between subtitle and body.
  --make-thumbnail,  -t size: Create thumbnail with a link to the original image
          Works only when the original image is larger than the specified size
          (see --threshold-size also)
          ex. -t 80x80
  --image-geometry,  -g size: resize image(s).
          The original image would be overwritten.
          Does not change the image size when the original image is smaller.
          ex. -g 800x800 (change the image size to "fit in" to 800x800 pixels)
  --use-image-ex,    -e: Recognize & auto-generate tags for image.rb (Enikki)
          or image_ex.rb (Enikki ex.) plugin
          Tag format: <%=image (serialno),"(alt text)"%>
          Serialno starts from 0. Will be automatically increased to match
          the real filename.
          Overrides -f option.
  --wiki-style,      -w: output image tags in Wiki style
          Suppress adding a whitespace before each tag
          Recognize Wiki style tags and rewrite
          Must be used with image.rb or image_ex.rb plugin.
  --read-exif,       -c: read "User Comment" tag from EXIF and use as ALT text
          If not specified, filename would be used as ALT text.
          Requires libexif and "exif" command.
  --hour-offset,     -o offset: hour_offset of tDiary
          (ex. -o +4  (do not change date until 28:00))
  --yearly-dir,      -y: put images in yearly separated directories
                         ( 2004/ , 2005/ , ...)
  --help,            -h: show detailed help & advanced options

  ============ advanced options ==============
  --convert-path,    -C fullpath_of_convert: location of "convert" command
          Use this option when ImageMagick's commands are not path-reachable.
          Assumes the same location for "identify" command as well.
  --exif-path,       -E fullpath_of_exif: location of "exif" command
          Enables --read-exif command as well.
          Use this option when "exif" command is not path-reachable.
  --remote-mode,     -R: upload images via update.rb using HTTP POST.
          Allows user to separate the mailserver and the webserver.
          Note: Thumbnails would not be posted.
  --remote-image-path,-D remote_dirname:
          Specify the image directory of the remote webserver.
          Required when using image_ex.rb with --remote-mode option.
  --remote-yearly-dir,-Y switch:
          Specify whether to put images in yearly separated directories
          at the remote webserver.
          Required when image_ex.rb with --remote-mode option.
          0: do not separate,  1: separate
  --preserve-local-images,   -P:
          Do not delete local image files.
          Effective only when --remote-mode is enabled.
  --class-name,      -n class_name:
          Class name for each photo (default: photo)
          Invalid when --use-image-ex or --wiki-style option is enabled.
  --add-div,         -v number_of_images:
          Encapsule all attached images with 
...
When specified number of (or more) images are attached. Set to 2 when not given. Specify 0 to disable. Automatically set to 0 when --wiki-style is enabled. ex. -v 3 (works only when 3 or more images are attached) --threshold-size, -z threshold_image_size: Make thumbnail if image size is larger. ex1. -z 120x140 ex2. -z 140 (same to 140x140) --image-format, -f format string: Specify the format string of the image tag These variables can be used in the format string: $0 : image serial number $1 : image url $2 : thumbnail image url (when -t is specified) $3 : class name $4 : ALT text (filename, or EXIF comment when -c is specified) ex. -f \"{{image \$0}}\" --use-original-name, -r: use original filename as ALT text when not specified --pass-filename, -p: Pass real filename (instead of serialno) to image_ex plugin (EXPERIMENTAL: Has no meanings so far) Effective only with -e option. --filter-mode, -d: print to stdout (does not call update.rb) --write-to-file, -b filename: writeout to file (does not call update.rb) --date-margin, -j date_margin: avoid writing diaries for future dates ex. -j 30 (default margin: 7) Output format: without -e/f, without -t: $4 without -e/f, with -t: $4 with -e: <%=image $0,"$4"%> with -w: {{image $0,"$4"}} (overrides -e) with -f: (specified format) (overrides -e, -w) Date specification format in mail body text: ex. when you want to append this mail to "2005 Feb 15" 's diary, add this line to mail body: _Date#2005-2-15 Example: posttdiary-ex.rb -w -a /home/hoge/htdocs/diary/tdiary.conf http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd) posttdiary-ex.rb -i /home/hoge/htdocs/diary-images/ -u http://yoursite.jp/~hoge/diary-images/ -t 120x120 -s -g 800x800 http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd) posttdiary-ex.rb -w -i /home/hoge/htdocs/diary-images/ -y -t 120x120 -s -g 800x800 http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd) posttdiary-ex.rb -R -i /home/hoge/tmp -D /home/hoge/htdocs/diary-images -Y -s -g 800x800 http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd)

Appendix:Quick set-up guide for image_ex plugin

For using image_ex.rb plugin, you should place image_ex.rb into the misc/plugin/ directory under your tdiary directory. You'd also wish to place image_size.rb in the same directory.
Then you must add the follwing entries to your tdiary.conf:
@options['image.dir'] = '/your/home/public_html/tdiary/images/' # directory to place the images (web-accecible)
@options['image.url'] = './images/'  # URL corresponding to image.dir
@options['image_ex.previewsize'] = 120 # size of the preview image
@options['image_ex.yearlydir'] = 0 # set to 1 when you wish to place the images in separate directories for each year
@options['image_ex.useresize'] = 1 # must be set to 1 when using ImageMagick
@options['image_ex.converttype'] = 0 # 0: convert to JPEG, 1: to PNG
@options['image_ex.thresholdsize'] = 160 # when the image is larger, generate thumbnail
@options['image_ex.convertedwidth'] = 160 # thumbnail width
@options['image_ex.convertedheight'] = 120 # thumbnail height
@options['image_ex.convertpath'] = "convert" #path to the "convert" command
You must also be sure that the "@secure" parameter is set to "false" in tdiary.conf.
Written by K.Sakurai (kei-tdiaryksakurai.)
Last Updated:1 Mar 2005