小编awe*_*son的帖子

如何使用ruby的net/imap库阅读电子邮件的正文?

也许我今天只是脑筋不好,但我突然无法弄清楚如何阅读带有ruby的net/imap库的电子邮件.我已经好几个小时了.我在google中输入了几个"ruby imap read body"的变种,并探索了很多网站.所有这些都有关于如何提取附件,同步电子邮件服务器,使用gmail等的示例......有些(如chilkat)实际上是共享软件库,可以为您执行此操作.我查看了net/imap文档,虽然有几个例子可以做所有事情但是阅读正文.

我曾经使用net/imap,但我只需要将收件箱中的附件下拉到目录.我已经在#ruby和#rubyonrails中要求无济于事 - 没有人能想出来.


imap=Net::IMAP.new('mail.xks.com') #of course these are not real
imap.login('web1_xk3','pxx2006')
imap.select('INBOX')
imap.search(["SENTSINCE",(Time.now-1.day).strftime("%d-%b-%Y")]).each do |msgid|
     body = imap.fetch(msgid,"BODY")[0].attr["BODY"]
     ##insert code for getting the text from the body here
     ##body.class is BodyTypeText 
end

PS虽然我确实在代码中引用了活动支持,但这是sans-rails,这意味着没有动作邮件

ruby imap

14
推荐指数
3
解决办法
2万
查看次数

C入门

我知道有许多教程可以在C开始.但是我很难应用这些知识.我一直以语言开始的方式是编写脚本.当然C不是脚本语言.

我的问题不在于学习C,而在于如何开始应用C.我可以写一个温度转换器或基于文本的RPG.也许是因为在python中我只是在somefile.py和chmod + x somefile.py && somefile.py中编写代码.我真的没有C的等效过程.每次我读到C时,它都是一个不同的标记的不同编译过程.当你已经使用更高级别的动态脚本语言时,有人可以给我一些关于应用C的最佳方法的明确方向吗?

顺便说一句...我问的是C而不是C++.

我通常使用的是OpenSuse 11或Ubuntu 9.04."我使用什么编译器"是问题的一部分.在python中,没有选择它只是"python somefile.py"与php或ruby相同.我不知道有选择.

c

7
推荐指数
2
解决办法
493
查看次数

预加载 webfonts 时如何确定正确的本地字体名称?

这篇文章:网络字体什么时候加载,你能预加载它们吗?, 表示使用 local 来利用已加载的字体。我找不到任何其他方式来预加载 webfonts。

但是,我不知道应该为本地引用使用哪些名称。在 MacOSX 中,多个变体显示为相同的字体名称。例如,我认为是本地的(“Helvetica Neue Light”)在字体书中可用为“Helvetica Neue”......我如何指代不同的变体?

@font-face {
  font-family: 'ProximaNova';
  font-weight: normal;
  font-style: normal;
  src: url('/fonts/proximanova/ProximaNova-Reg-webfont.eot');
  src:  local("Proxima Nova Regular"), url('/fonts/proximanova/ProximaNova-Reg-webfont.eot?#iefix') format('embedded-opentype'),
       url('/fonts/proximanova/ProximaNova-Reg-webfont.woff') format('woff'),
       url('/fonts/proximanova/ProximaNova-Reg-webfont.ttf') format('truetype'),
       url('/fonts/proximanova/ProximaNova-Reg-webfont.svg#webfont') format('svg');
}

@font-face {
  font-family: 'ProximaNova';
  font-weight: $light_weight;
  font-style: normal;
  src: url('/fonts/proximanova/ProximaNova-Light-webfont.eot');
  src: url('/fonts/proximanova/ProximaNova-Light-webfont.eot?#iefix') format('embedded-opentype'),
       url('/fonts/proximanova/ProximaNova-Light-webfont.woff') format('woff'),
       url('/fonts/proximanova/ProximaNova-Light-webfont.ttf') format('truetype'),
       url('/fonts/proximanova/ProximaNova-Light-webfont.svg#webfont') format('svg');
}
Run Code Online (Sandbox Code Playgroud)

所有变化仍会导致对 chrome 中的 woff 文件的请求。此外,我找不到有关 Web 字体的任何最近或当前最佳实践或如何优化其性能,我该如何阻止这些请求?

css performance fonts webfonts

7
推荐指数
1
解决办法
2957
查看次数

如何在Ruby Net中处理多部分http响应:HTTP?

关于如何生成多部分响应或执行多部分文件上传,有很多信息.我似乎无法找到有关如何处理多部分http响应的任何信息.这是我正在使用的多部分http响应的一些IRB输出.

>> response.http.content_type
=> "multipart/related"
>> response.http.body[0..2048]
=> "\r\n------=_Part_3_806633756.1271797659309\r\nContent-Type: text/xml; charset=UTF-8\r\nContent-Transfer-Encoding: binary\r\nContent-Id: <A0FCC4333C6D0FCA346B97FAB6B61818>\r\n\r\n<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:runReportResponse soapenv:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:ns1="http://192.168.1.200:8080/jasperserver/services/repository"><ns2:result xmlns:ns2="http://www.w3.org/2003/05/soap-rpc">runReportReturn</ns2:result><runReportReturn xsi:type="xsd:string">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;operationResult version=&quot;2.0.1&quot;&gt;\n\t&lt;returnCode&gt;&lt;![CDATA[0]]&gt;&lt;/returnCode&gt;\n&lt;/operationResult&gt;\n</runReportReturn></ns1:runReportResponse></soapenv:Body></soapenv:Envelope>\r\n------=_Part_3_806633756.1271797659309\r\nContent-Type: application/pdf\r\nContent-Transfer-Encoding: binary\r\nContent-Id: <report>\r\n\r\n%PDF-1.4\n%\342\343\317\323\n3 0 obj 
Run Code Online (Sandbox Code Playgroud)

ruby soap http multipart

5
推荐指数
1
解决办法
1183
查看次数

你如何在angularjs服务中模拟$ rootScope?

鉴于我有这样的服务.

angular.module('app')
  .factory('Session', function Session($rootScope, $cookieStore) {
    var user;

    if (user = $cookieStore.get('user')) {
      $rootScope.currentUser = user;
    }

});
Run Code Online (Sandbox Code Playgroud)

和测试

'use strict';

describe('Service: Session', function () {
  var Session,
    _rootScope,
    _cookieStore;

  beforeEach(module('app'));

  beforeEach(module(function($provide, $injector) {
    _rootScope = $injector.get('$rootScope').$new();
    _cookieStore = {
      get: angular.noop
    };
    $provide.value('$rootScope', _rootScope);
    $provide.value('$cookieStore', _cookieStore);
  }));

  beforeEach(inject(function(_Session_) {
    Session = _Session_;
  }));

  it('transfers the cookie under user into the currentUser', function() {
    spyOn(_cookieStore, 'get').andReturn('user');
    inject(function(_Session_) {
      Session = _Session_;
    });
    expect(_rootScope.currentUser).toEqual('user');
  });
});
Run Code Online (Sandbox Code Playgroud)

我最终得到了

Error: [$injector:unpr] Unknown …
Run Code Online (Sandbox Code Playgroud)

unit-testing angularjs angularjs-service

3
推荐指数
1
解决办法
2300
查看次数